[PATCH weston v3 29/36] libweston: cancel idle_repaint on output destroy

Pekka Paalanen ppaalanen at gmail.com
Tue Oct 31 11:48:39 UTC 2017


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

If the idle_repaint() callback has been scheduled when a weston_output
gets destroyed, the callback will hit use-after-free. I have encountered
this when migrating the wayland backend to the head-based API, using
--sprawl, and closing/disconnecting one of the parent compositor
outputs.

Store the idle_repaint callback source, and destroy it in
weston_output_release(), ensuring we don't get a stale call to
start_repaint_loop later.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 libweston/compositor.c | 8 +++++++-
 libweston/compositor.h | 3 +++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index cf40e0d0..ca0870a3 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -2583,6 +2583,7 @@ idle_repaint(void *data)
 
 	assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE);
 	output->repaint_status = REPAINT_AWAITING_COMPLETION;
+	output->idle_repaint_source = NULL;
 	output->start_repaint_loop(output);
 }
 
@@ -2707,7 +2708,9 @@ weston_output_schedule_repaint(struct weston_output *output)
 		return;
 
 	output->repaint_status = REPAINT_BEGIN_FROM_IDLE;
-	wl_event_loop_add_idle(loop, idle_repaint, output);
+	assert(!output->idle_repaint_source);
+	output->idle_repaint_source = wl_event_loop_add_idle(loop, idle_repaint,
+							     output);
 	TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END);
 }
 
@@ -5594,6 +5597,9 @@ weston_output_release(struct weston_output *output)
 
 	output->destroying = 1;
 
+	if (output->idle_repaint_source)
+		wl_event_source_remove(output->idle_repaint_source);
+
 	if (output->enabled)
 		weston_compositor_remove_output(output);
 
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 9d435e5a..017878a0 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -215,6 +215,9 @@ struct weston_output {
 	 *  next repaint should be run */
 	struct timespec next_repaint;
 
+	/** For cancelling the idle_repaint callback on output destruction. */
+	struct wl_event_source *idle_repaint_source;
+
 	struct weston_output_zoom zoom;
 	int dirty;
 	struct wl_signal frame_signal;
-- 
2.13.6



More information about the wayland-devel mailing list