From e4ed64b7313fb8f5199b312852ecef2b3f238c15 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Wed, 28 Oct 2015 09:56:46 +0100 Subject: [PATCH] wayland: free the frame in frame_release_callback() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This basically reverts 62c3888b76afc69f714a020957e8c5dd9d98f561 (wayland: decouple wl_buffer from frame). Otherwise the frame may be overwritten while it is still used by the compositer: The frame done callback (frame_done_callback()) is called, when the compositor is done processing the frame and hands it to the hardware. The buffer release callback (frame_release_callback()) is called when the buffer memory is no longer used. This can be quite some time later: E.g. if weston (with the DRM backend) puts the buffer on a hardware plane, then then buffer release callback is called when the kernel is done with the buffer. This is usually when the next frame is shown, so most likely after the frame done callback for the next frame! Since 70eff01d36a2870cbf06ffb91c2a941e8cb6b804 "wayland: sync() when destroy()" the mentioned possible leak should no longer be a problem, so reverting this change should cause no leaking buffers. Signed-off-by: Víctor Manuel Jáquez Leal https://bugzilla.gnome.org/show_bug.cgi?id=758848 Signed-off-by: Víctor Manuel Jáquez Leal --- gst-libs/gst/vaapi/gstvaapiwindow_wayland.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c index aeffc38..aab4879 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c @@ -368,7 +368,6 @@ frame_done_callback (void *data, struct wl_callback *callback, uint32_t time) GST_VAAPI_WINDOW_WAYLAND_GET_PRIVATE (frame->window); g_atomic_pointer_compare_and_exchange (&priv->last_frame, frame, NULL); - frame_state_free (frame); g_atomic_int_dec_and_test (&priv->num_frames_pending); } @@ -380,6 +379,7 @@ static void frame_release_callback (void *data, struct wl_buffer *wl_buffer) { wl_buffer_destroy (wl_buffer); + frame_state_free (data); } static const struct wl_buffer_listener frame_buffer_listener = { @@ -542,11 +542,8 @@ gst_vaapi_window_wayland_render (GstVaapiWindow * window, priv->opaque_region = NULL; } - /* @TODO: It is not OK to use internal event_queue here, since there - * may still be a WL_BUFFER_RELEASE event when we destroy the - * event_queue in gst_vaapi_window_wayland_destroy (). */ wl_proxy_set_queue ((struct wl_proxy *) buffer, priv->event_queue); - wl_buffer_add_listener (buffer, &frame_buffer_listener, NULL); + wl_buffer_add_listener (buffer, &frame_buffer_listener, frame); frame->callback = wl_surface_frame (priv->surface); wl_callback_add_listener (frame->callback, &frame_callback_listener, frame); -- 2.7.4