comp-wayland: use safe foreach when destroying outputs
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 21 May 2014 16:20:02 +0000 (09:20 -0700)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Fri, 23 May 2014 06:57:02 +0000 (09:57 +0300)
wl_list_for_each dereference's output to increment the
next iteration of the loop.  However, output is free'd
inside the loop resulting in a dereference to free'd
memory.

Use wl_list_for_each_safe instead, which is designed to
handle this kind of pattern.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Reviewed-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
src/compositor-wayland.c

index a08b71a..76e5396 100644 (file)
@@ -1997,9 +1997,9 @@ err_free:
 static void
 wayland_compositor_destroy(struct wayland_compositor *c)
 {
-       struct weston_output *output;
+       struct weston_output *output, *next;
 
-       wl_list_for_each(output, &c->base.output_list, link)
+       wl_list_for_each_safe(output, next, &c->base.output_list, link)
                wayland_output_destroy(output);
 
        c->base.renderer->destroy(&c->base);