From 7bc1025d912b7ad2aac4f45802ce4a19f5e49bef Mon Sep 17 00:00:00 2001 From: Fernando Tagawa Date: Thu, 2 May 2024 20:39:08 -0300 Subject: [PATCH] Wayland: Fix segfault when exiting with `ctrl+q` (#11324) Release Notes: - N/A When closing with `ctrl-q`, drop_window is not called and results in a segfault. --- .../gpui/src/platform/linux/wayland/client.rs | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/crates/gpui/src/platform/linux/wayland/client.rs b/crates/gpui/src/platform/linux/wayland/client.rs index 685b91fb4c0defa7d63976670a5ec86a35f9e3dc..f2ab74bfffe257d33a5aaa0a708d0d8c58c227cc 100644 --- a/crates/gpui/src/platform/linux/wayland/client.rs +++ b/crates/gpui/src/platform/linux/wayland/client.rs @@ -199,18 +199,6 @@ impl WaylandClientStatePtr { } } if state.windows.is_empty() { - // Drop the clipboard to prevent a seg fault after we've closed all Wayland connections. - state.clipboard = None; - state.primary = None; - if let Some(wl_pointer) = &state.wl_pointer { - wl_pointer.release(); - } - if let Some(cursor_shape_device) = &state.cursor_shape_device { - cursor_shape_device.destroy(); - } - if let Some(data_device) = &state.data_device { - data_device.release(); - } state.common.signal.stop(); } } @@ -219,6 +207,26 @@ impl WaylandClientStatePtr { #[derive(Clone)] pub struct WaylandClient(Rc>); +impl Drop for WaylandClient { + fn drop(&mut self) { + let mut state = self.0.borrow_mut(); + state.windows.clear(); + + // Drop the clipboard to prevent a seg fault after we've closed all Wayland connections. + state.primary = None; + state.clipboard = None; + if let Some(wl_pointer) = &state.wl_pointer { + wl_pointer.release(); + } + if let Some(cursor_shape_device) = &state.cursor_shape_device { + cursor_shape_device.destroy(); + } + if let Some(data_device) = &state.data_device { + data_device.release(); + } + } +} + const WL_DATA_DEVICE_MANAGER_VERSION: u32 = 3; const WL_OUTPUT_VERSION: u32 = 2;