From 66c19a21d82f30ec099c7dbaf8f76e8f53e409e0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 16 Sep 2025 15:25:14 +1000 Subject: [PATCH] Fix #145557: Memory leak on exit with custom wayland cursor shapes While the leak only occurred on GNOME, there is no guarantee the compositor releases cursor buffer before exiting. --- intern/ghost/intern/GHOST_SystemWayland.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index f4e80292bf0..494e46d9b7b 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -6986,10 +6986,6 @@ static void gwl_registry_wl_seat_remove(GWL_Display *display, void *user_data, c zwp_tablet_seat_v2_destroy(seat->wp.tablet_seat); } - if (seat->cursor.custom_data) { - munmap(seat->cursor.custom_data, seat->cursor.custom_data_size); - } - /* Disable all capabilities as a way to free: * - `seat.wl_pointer` (and related cursor variables). * - `seat.wl_touch`. @@ -6999,6 +6995,20 @@ static void gwl_registry_wl_seat_remove(GWL_Display *display, void *user_data, c gwl_seat_capability_keyboard_disable(seat); gwl_seat_capability_touch_disable(seat); + /* Run after tablet & input devices have been disabled + * to ensure the buffer from a *visible* cursor never destroyed. + * + * Note that most compositors will have already releases the buffer, + * in that case this will have been set to null. + * However this isn't guaranteed, see: #145557. */ + if (seat->cursor.wl.buffer) { + wl_buffer_destroy(seat->cursor.wl.buffer); + } + + if (seat->cursor.custom_data) { + munmap(seat->cursor.custom_data, seat->cursor.custom_data_size); + } + /* Un-referencing checks for nullptr case. */ xkb_state_unref(seat->xkb.state); xkb_state_unref(seat->xkb.state_empty);