diff --git a/ui/base/x/x11_whole_screen_move_loop.cc b/ui/base/x/x11_whole_screen_move_loop.cc index 71ec09e003fcf..d63595de0b105 100644 --- a/ui/base/x/x11_whole_screen_move_loop.cc +++ b/ui/base/x/x11_whole_screen_move_loop.cc @@ -237,7 +237,13 @@ void X11WholeScreenMoveLoop::EndMoveLoop() { // Restore the previous dispatcher. nested_dispatcher_.reset(); + // The delegate callout can synchronously destroy |this| (e.g. the source + // X11Window is closed while handling the SendXdndLeave short-circuit). + base::WeakPtr alive(weak_factory_.GetWeakPtr()); delegate_->OnMoveLoopEnded(); + if (!alive) { + return; + } grab_input_window_events_.Reset(); connection->DestroyWindow({grab_input_window_}); grab_input_window_ = x11::Window::None;