From 8a79713a34344d0d7ed1dd8a96f1d3407359c727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Bruguera=20Mic=C3=B3?= Date: Sun, 7 Jul 2024 16:10:21 +0000 Subject: [PATCH] wayland: Free `struct window` and `struct surf_output` objects Make sure that we release the memory used by each `wl_list` node that was previously allocated with `calloc`. I'm not sure if freeing the memory of the nodes without removing it from the `wl_list` first could cause any problem so prefer removing it from the list before releasing the memory. --- lib/renderers/wayland/wayland.c | 12 +++++++----- lib/renderers/wayland/window.c | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/renderers/wayland/wayland.c b/lib/renderers/wayland/wayland.c index f2b8fdd..c8e38bb 100644 --- a/lib/renderers/wayland/wayland.c +++ b/lib/renderers/wayland/wayland.c @@ -465,10 +465,11 @@ wl_surface_leave(void *data, struct wl_surface *wl_surface, (void)wl_surface; struct window *window = data; - struct surf_output *surf_output; - wl_list_for_each(surf_output, &window->surf_outputs, link) { + struct surf_output *surf_output, *surf_output_tmp; + wl_list_for_each_safe(surf_output, surf_output_tmp, &window->surf_outputs, link) { if (surf_output->output->output == wl_output) { wl_list_remove(&surf_output->link); + free(surf_output); break; } } @@ -484,11 +485,12 @@ static const struct wl_surface_listener surface_listener = { static void destroy_windows(struct wayland *wayland) { - struct window *window; - wl_list_for_each(window, &wayland->windows, link) { + struct window *window, *window_tmp; + wl_list_for_each_safe(window, window_tmp, &wayland->windows, link) { + wl_list_remove(&window->link); bm_wl_window_destroy(window); + free(window); } - wl_list_init(&wayland->windows); } void diff --git a/lib/renderers/wayland/window.c b/lib/renderers/wayland/window.c index 0043c2b..ee044fb 100644 --- a/lib/renderers/wayland/window.c +++ b/lib/renderers/wayland/window.c @@ -297,6 +297,12 @@ bm_wl_window_destroy(struct window *window) if (window->surface) wl_surface_destroy(window->surface); + + struct surf_output *surf_output, *surf_output_tmp; + wl_list_for_each_safe(surf_output, surf_output_tmp, &window->surf_outputs, link) { + wl_list_remove(&surf_output->link); + free(surf_output); + } } static void