[PATCH] client: Fix handling display->reader_count if poll fails

Kristian Høgsberg hoegsberg at gmail.com
Wed Sep 11 14:39:56 PDT 2013


On Wed, Sep 11, 2013 at 07:21:17PM +0100, Neil Roberts wrote:
> In wl_display_dispatch_queue, if poll fails then it would previously
> return immediately and leak a reference in display->reader_count. Then
> if the application ignores the error and tries to read again it will
> block forever. This can happen for example if the poll fails with
> EINTR which the application might consider to be a recoverable error.
> This patch just makes it decrement the reader count when poll fails.

Oh wow, tricky.  Yes, that's the right idea, but we need to call
wl_display_cancel_read() instead of just decrementing to make sure we
grab the lock when we decrement and wake up sleeping readers in case
we were the last reader.

Kristian

> ---
>  src/wayland-client.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index 48f06c7..576a773 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -1224,8 +1224,10 @@ wl_display_dispatch_queue(struct wl_display *display,
>  
>  	pfd[0].fd = display->fd;
>  	pfd[0].events = POLLIN;
> -	if (poll(pfd, 1, -1) == -1)
> +	if (poll(pfd, 1, -1) == -1) {
> +		display->reader_count--;
>  		return -1;
> +	}
>  
>  	pthread_mutex_lock(&display->mutex);
>  
> -- 
> 1.8.3.1
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list