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>
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;
}
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;
}