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.
This commit is contained in:
Joan Bruguera Micó 2024-07-07 16:10:21 +00:00 committed by Jari Vetoniemi
parent 96d206a815
commit 8a79713a34
2 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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