From 024205556448393e64e5020e41e7be498535c566 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sat, 8 Jul 2023 20:31:09 -0500 Subject: [PATCH] wayland: fix memory leak with multiple monitors Very dumb. I can't remember if it was always like this or if I broke it at some point, but clearly each wl_output should just be freed in remove_output. Freeing it if it happens to be wl->current_output only works for that one monitor, so remove that whole line. This has to happen before we close the wayland connection so reorder the uninit a little bit. --- video/out/wayland_common.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 28cd6eb55b..36dc0f6934 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -1652,6 +1652,7 @@ static void remove_output(struct vo_wayland_output *out) MP_VERBOSE(out->wl, "Deregistering output %s %s (0x%x)\n", out->make, out->model, out->id); wl_list_remove(&out->link); + wl_output_destroy(out->output); talloc_free(out->make); talloc_free(out->model); talloc_free(out); @@ -2314,9 +2315,6 @@ void vo_wayland_uninit(struct vo *vo) if (wl->subcompositor) wl_subcompositor_destroy(wl->subcompositor); - if (wl->current_output && wl->current_output->output) - wl_output_destroy(wl->current_output->output); - if (wl->cursor_surface) wl_surface_destroy(wl->cursor_surface); @@ -2431,6 +2429,10 @@ void vo_wayland_uninit(struct vo *vo) if (wl->xkb_state) xkb_state_unref(wl->xkb_state); + struct vo_wayland_output *output, *tmp; + wl_list_for_each_safe(output, tmp, &wl->output_list, link) + remove_output(output); + if (wl->display) { close(wl_display_get_fd(wl->display)); wl_display_disconnect(wl->display); @@ -2438,10 +2440,6 @@ void vo_wayland_uninit(struct vo *vo) munmap(wl->format_map, wl->format_size); - struct vo_wayland_output *output, *tmp; - wl_list_for_each_safe(output, tmp, &wl->output_list, link) - remove_output(output); - for (int n = 0; n < 2; n++) close(wl->wakeup_pipe[n]); talloc_free(wl);