Oh, sorry, I wasn't sure how to reproduce the other case. (Did you see my last email? I don't know if I should write a new client, or if I can test it with existing ones.)<div>I have some time, I'm just not familiar with the code :)</div>
<div><br><div class="gmail_quote">On Sun, Jul 22, 2012 at 8:45 AM, Kristian Høgsberg <span dir="ltr"><<a href="mailto:hoegsberg@gmail.com" target="_blank">hoegsberg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Tue, Jul 10, 2012 at 02:35:10PM -0400, Kristian Høgsberg wrote:<br>
> On Tue, Jul 10, 2012 at 09:28:11AM -0700, Dima Ryazanov wrote:<br>
> > I see the following use-after-free when a client disconnects:<br>
> ><br>
> > ==21822== Invalid write of size 8<br>
> > ==21822== at 0x54A8F74: wl_list_remove (wayland-util.c:51)<br>
> > ==21822== by 0x409C87: destroy_frame_callback (compositor.c:1362)<br>
> > ==21822== by 0x56B44E7: destroy_resource (wayland-server.c:427)<br>
> > ==21822== by 0x54A9557: for_each_helper (wayland-util.c:268)<br>
> > ==21822== by 0x54A9593: wl_map_for_each (wayland-util.c:274)<br>
> > ==21822== by 0x56B4640: wl_client_destroy (wayland-server.c:474)<br>
> > ==21822== by 0x56B3E52: wl_client_connection_data (wayland-server.c:231)<br>
> > ==21822== by 0x56B7BD9: wl_event_source_fd_dispatch (event-loop.c:79)<br>
> > ==21822== by 0x56B85AE: wl_event_loop_dispatch (event-loop.c:410)<br>
> > ==21822== by 0x56B5C05: wl_display_run (wayland-server.c:1090)<br>
> > ==21822== by 0x40ECBE: main (compositor.c:3394)<br>
> > ==21822== Address 0xc793d98 is 616 bytes inside a block of size 680 free'd<br>
> > ==21822== at 0x4C2A82E: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)<br>
> > ==21822== by 0x407DAB: destroy_surface (compositor.c:689)<br>
> > ==21822== by 0x56B44E7: destroy_resource (wayland-server.c:427)<br>
> > ==21822== by 0x54A9557: for_each_helper (wayland-util.c:268)<br>
> > ==21822== by 0x54A9593: wl_map_for_each (wayland-util.c:274)<br>
> > ==21822== by 0x56B4640: wl_client_destroy (wayland-server.c:474)<br>
> > ==21822== by 0x56B3E52: wl_client_connection_data (wayland-server.c:231)<br>
> > ==21822== by 0x56B7BD9: wl_event_source_fd_dispatch (event-loop.c:79)<br>
> > ==21822== by 0x56B85AE: wl_event_loop_dispatch (event-loop.c:410)<br>
> > ==21822== by 0x56B5C05: wl_display_run (wayland-server.c:1090)<br>
> > ==21822== by 0x40ECBE: main (compositor.c:3394)<br>
> ><br>
> > This seems to fix it for me, though I've no idea if it's actually correct.<br>
><br>
> It's actually an elegant fix for the case you hit (client disconnect),<br>
> since the callback objects on the list will be destroyed by the<br>
> resource cleanup, so all we need to to is take the list head out to<br>
> prevent the callback objects from accessing that freed memory as<br>
> they're destroyed.<br>
><br>
> We have a different case to consider though. When a surface is<br>
> explicitly destroyed by calling surface.destroy(), we still need to<br>
> destroy pending callbacks, and that case the resource system wont do<br>
> it for us. So we need to iterate through the list and free them<br>
> manually.<br>
<br>
</div></div>I was hoping you'd have time to implement the above, but I've pushed<br>
1e51fecdf5ade44c77de325679f1e010d8ba4273 now, which should fix the<br>
problem and handle the regular destroy case.<br>
<span class="HOEnZb"><font color="#888888"><br>
Kristian<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> Kristian<br>
><br>
> > ---<br>
> > src/compositor.c | 2 ++<br>
> > 1 file changed, 2 insertions(+)<br>
> ><br>
> > diff --git a/src/compositor.c b/src/compositor.c<br>
> > index 678e0bd..9fe561a 100644<br>
> > --- a/src/compositor.c<br>
> > +++ b/src/compositor.c<br>
> > @@ -686,6 +686,8 @@ destroy_surface(struct wl_resource *resource)<br>
> > if (!region_is_undefined(&surface->input))<br>
> > pixman_region32_fini(&surface->input);<br>
> ><br>
> > + wl_list_remove(&surface->frame_callback_list);<br>
> > +<br>
> > free(surface);<br>
> > }<br>
> ><br>
> > --<br>
> > 1.7.9.5<br>
> ><br>
> > _______________________________________________<br>
> > wayland-devel mailing list<br>
> > <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
> > <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</div></div></blockquote></div><br></div>