wayland: Don't cancel a roundtrip when any event is received
authorJonas Ådahl <jadahl@gmail.com>
Tue, 25 Dec 2012 12:01:08 +0000 (13:01 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 3 Jan 2013 16:44:55 +0000 (11:44 -0500)
Since wl_display_dispatch_queue() 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 the
roundtrip does an early return and the callback later writes to the then
out of scope stack allocated `done' parameter.

Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
src/egl/drivers/dri2/platform_wayland.c
src/gallium/state_trackers/egl/wayland/native_wayland.c

index ba54286b7bc58734a7c47165a132cc99b440ab66..10a0f0830d8d536eb2c1406c2f26d45e1e8d32df 100644 (file)
@@ -70,6 +70,9 @@ roundtrip(struct dri2_egl_display *dri2_dpy)
    while (ret != -1 && !done)
       ret = wl_display_dispatch_queue(dri2_dpy->wl_dpy, dri2_dpy->wl_queue);
 
+   if (!done)
+      wl_callback_destroy(callback);
+
    return ret;
 }
 
index 560e40d4cee81a0df75ecd4eae2f2b08317815da..941a0944518425ab64d0d963ebbeb8377d68fc12 100644 (file)
@@ -57,9 +57,12 @@ wayland_roundtrip(struct wayland_display *display)
    callback = wl_display_sync(display->dpy);
    wl_callback_add_listener(callback, &sync_listener, &done);
    wl_proxy_set_queue((struct wl_proxy *) callback, display->queue);
-   while (ret == 0 && !done)
+   while (ret != -1 && !done)
       ret = wl_display_dispatch_queue(display->dpy, display->queue);
 
+   if (!done)
+      wl_callback_destroy(callback);
+
    return ret;
 }