From d7a63fdbfb8fcfcf4b2a81bc4773958ebd785d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 26 Nov 2012 23:25:53 +0100 Subject: [PATCH] client: Don't cancel a roundtrip when any event is received MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since wl_display_dispatch() returns the number of processed events or -1 on error, only cancel the roundtrip if an -1 is returned. This also fixes a potential memory corruption bug happening when wl_display_roundtrip() does an early return and the callback later writes to the then out of scope stack allocated `done' parameter. Introduced by 33b7637b4500a682018b503837b8aca9afae36f2. Signed-off-by: Jonas Ã…dahl --- src/wayland-client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wayland-client.c b/src/wayland-client.c index 5fecc018..5ba2c454 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -649,9 +649,12 @@ wl_display_roundtrip(struct wl_display *display) done = 0; callback = wl_display_sync(display); wl_callback_add_listener(callback, &sync_listener, &done); - while (!done && !ret) + while (!done && ret >= 0) ret = wl_display_dispatch(display); + if (ret == -1 && !done) + wl_callback_destroy(callback); + return ret; }