From 0930282baa975efccf86f3d95cbebc0f575addd3 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Thu, 14 Dec 2023 16:08:54 +0100 Subject: [PATCH] tests/wayland-test-clients: Destroy WaylandBuffers when released Instead of forcing every user of WaylandBuffer to create a listener and destroy the wl_resource and the WaylandBuffer object, provide a default listener which does it for the user. Part-of: --- .../wayland-test-client-utils.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c b/src/tests/wayland-test-clients/wayland-test-client-utils.c index c0bbc796b..132e8d956 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.c +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c @@ -793,6 +793,20 @@ wayland_buffer_init (WaylandBuffer *buffer) { } +static void +handle_buffer_release (void *user_data, + struct wl_buffer *buffer_resource) +{ + WaylandBuffer *buffer = WAYLAND_BUFFER (user_data); + + wl_buffer_destroy (buffer_resource); + g_object_unref (buffer); +} + +static const struct wl_buffer_listener default_buffer_listener = { + handle_buffer_release +}; + WaylandBuffer * wayland_buffer_create (WaylandDisplay *display, const struct wl_buffer_listener *listener, @@ -824,6 +838,9 @@ wayland_buffer_create (WaylandDisplay *display, if (!wayland_buffer_allocate (buffer, n_modifiers, modifiers, bo_flags)) return NULL; + if (!listener) + listener = &default_buffer_listener; + wl_buffer_add_listener (priv->buffer, listener, buffer); return g_steal_pointer (&buffer);