From 9901d49fa52bb8405078537fe95c9aa8c6bdcf73 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 21 Apr 2021 10:30:04 +0200 Subject: [PATCH] render/pixman: cleanup when renderer is destroyed We were leaking wlr_pixman_buffers and a wlr_drm_format_set. --- render/pixman/renderer.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/render/pixman/renderer.c b/render/pixman/renderer.c index 466b71d0..586af99c 100644 --- a/render/pixman/renderer.c +++ b/render/pixman/renderer.c @@ -61,9 +61,7 @@ static const struct wlr_texture_impl texture_impl = { struct wlr_pixman_texture *pixman_create_texture( struct wlr_texture *wlr_texture, struct wlr_pixman_renderer *renderer); -static void handle_destroy_buffer(struct wl_listener *listener, void *data) { - struct wlr_pixman_buffer *buffer = - wl_container_of(listener, buffer, buffer_destroy); +static void destroy_buffer(struct wlr_pixman_buffer *buffer) { wl_list_remove(&buffer->link); wl_list_remove(&buffer->buffer_destroy.link); @@ -72,6 +70,12 @@ static void handle_destroy_buffer(struct wl_listener *listener, void *data) { free(buffer); } +static void handle_destroy_buffer(struct wl_listener *listener, void *data) { + struct wlr_pixman_buffer *buffer = + wl_container_of(listener, buffer, buffer_destroy); + destroy_buffer(buffer); +} + static struct wlr_pixman_buffer *create_buffer( struct wlr_pixman_renderer *renderer, struct wlr_buffer *wlr_buffer) { struct wlr_pixman_buffer *buffer = calloc(1, sizeof(*buffer)); @@ -348,6 +352,19 @@ static bool pixman_bind_buffer(struct wlr_renderer *wlr_renderer, return true; } +static void pixman_destroy(struct wlr_renderer *wlr_renderer) { + struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer); + + struct wlr_pixman_buffer *buffer, *buffer_tmp; + wl_list_for_each_safe(buffer, buffer_tmp, &renderer->buffers, link) { + destroy_buffer(buffer); + } + + wlr_drm_format_set_finish(&renderer->drm_formats); + + free(renderer); +} + static const struct wlr_renderer_impl renderer_impl = { .begin = pixman_begin, .clear = pixman_clear, @@ -358,6 +375,7 @@ static const struct wlr_renderer_impl renderer_impl = { .get_render_formats = pixman_get_render_formats, .texture_from_pixels = pixman_texture_from_pixels, .bind_buffer = pixman_bind_buffer, + .destroy = pixman_destroy, }; struct wlr_renderer *wlr_pixman_renderer_create(void) {