gpui: Fix crash caused by ownership leak (#19185)

wannacu created

- Closes #18811

Release Notes:

- N/A

Change summary

crates/gpui/src/platform/linux/x11/client.rs | 28 ++++++++++++---------
1 file changed, 16 insertions(+), 12 deletions(-)

Detailed changes

crates/gpui/src/platform/linux/x11/client.rs 🔗

@@ -675,11 +675,12 @@ impl X11Client {
                         }
                     }
                 } else if event.type_ == state.atoms.XdndLeave {
-                    window.handle_input(PlatformInput::FileDrop(FileDropEvent::Pending {
-                        position: state.xdnd_state.position,
-                    }));
+                    let position = state.xdnd_state.position;
+                    drop(state);
+                    window
+                        .handle_input(PlatformInput::FileDrop(FileDropEvent::Pending { position }));
                     window.handle_input(PlatformInput::FileDrop(FileDropEvent::Exited {}));
-                    state.xdnd_state = Xdnd::default();
+                    self.0.borrow_mut().xdnd_state = Xdnd::default();
                 } else if event.type_ == state.atoms.XdndPosition {
                     if let Ok(pos) = state
                         .xcb_connection
@@ -709,9 +710,10 @@ impl X11Client {
                         state.xdnd_state.other_window,
                         arg4,
                     );
-                    window.handle_input(PlatformInput::FileDrop(FileDropEvent::Pending {
-                        position: state.xdnd_state.position,
-                    }));
+                    let position = state.xdnd_state.position;
+                    drop(state);
+                    window
+                        .handle_input(PlatformInput::FileDrop(FileDropEvent::Pending { position }));
                 } else if event.type_ == state.atoms.XdndDrop {
                     xdnd_send_finished(
                         &state.xcb_connection,
@@ -719,10 +721,11 @@ impl X11Client {
                         event.window,
                         state.xdnd_state.other_window,
                     );
-                    window.handle_input(PlatformInput::FileDrop(FileDropEvent::Submit {
-                        position: state.xdnd_state.position,
-                    }));
-                    state.xdnd_state = Xdnd::default();
+                    let position = state.xdnd_state.position;
+                    drop(state);
+                    window
+                        .handle_input(PlatformInput::FileDrop(FileDropEvent::Submit { position }));
+                    self.0.borrow_mut().xdnd_state = Xdnd::default();
                 }
             }
             Event::SelectionNotify(event) => {
@@ -751,8 +754,9 @@ impl X11Client {
                                 position: state.xdnd_state.position,
                                 paths: crate::ExternalPaths(paths),
                             });
+                            drop(state);
                             window.handle_input(input);
-                            state.xdnd_state.retrieved = true;
+                            self.0.borrow_mut().xdnd_state.retrieved = true;
                         }
                         Err(_) => {}
                     }