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.
This commit is contained in:
Campbell Barton
2025-09-16 15:25:14 +10:00
parent 96d7c5c4cd
commit 66c19a21d8

View File

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