[PATCH weston] Destroy resources when destroying an output

Neil Roberts neil at linux.intel.com
Thu May 8 10:38:25 PDT 2014


When an output is destroyed it now also destroys any resources that
were pointing to it. Otherwise if the resource is destroyed after the
output then the resource would try to remove itself from the resource
list but the head of the resource list would no longer be valid and it
would write to invalid memory.

This was found using Valgrind. It looks like there is a similar
problem for weston_pointer_destroy and in that case there is even a
comment suggesting we should do something about it.

https://bugs.freedesktop.org/show_bug.cgi?id=78415
---
 src/compositor.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/compositor.c b/src/compositor.c
index cd1ca9a..4162315 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3110,6 +3110,8 @@ weston_compositor_remove_output(struct weston_compositor *compositor,
 WL_EXPORT void
 weston_output_destroy(struct weston_output *output)
 {
+	struct wl_resource *resource, *tmp;
+
 	output->destroying = 1;
 
 	weston_compositor_remove_output(output->compositor, output);
@@ -3124,6 +3126,9 @@ weston_output_destroy(struct weston_output *output)
 	output->compositor->output_id_pool &= ~(1 << output->id);
 
 	wl_global_destroy(output->global);
+
+	wl_resource_for_each_safe(resource, tmp, &output->resource_list)
+		wl_resource_destroy(resource);
 }
 
 static void
-- 
1.9.0



More information about the wayland-devel mailing list