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

Neil Roberts neil at linux.intel.com
Wed Sep 25 02:39:12 PDT 2013

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 makes it cancel the read so the reader_count will be
decremented when poll fails.

Ok, here is a second version of the patch which calls
wl_display_cancel_read as you suggested. Thanks for the review.

 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 cad587d..a20a71e 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) {
+		wl_display_cancel_read(display);
 		return -1;
+	}

More information about the wayland-devel mailing list