diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc index c58f75ab1bfba..29413c2e8598d 100644 --- a/ui/views/controls/menu/menu_controller.cc +++ b/ui/views/controls/menu/menu_controller.cc @@ -2527,7 +2527,16 @@ void MenuController::OpenMenuImpl(MenuItemView* item, bool show) { } else { params.context = owner_; } + base::WeakPtr weak_this = AsWeakPtr(); item->GetSubmenu()->ShowAt(params); + // ShowAt() can synchronously re-enter and destroy `this` and the + // MenuItemView tree (e.g. focus changes during ShowInactive() on macOS + // reach MenuRunnerImpl::OnMenuClosed()). The inner frames at + // SubmenuView::ShowAt() and MenuHost::ShowMenuHost() guard themselves, + // but this frame and its callers (OpenMenu / CommitPendingSelection / + // SetSelection / Run) do not. Crash safely instead of dereferencing + // freed `item` below and writing to freed `this->showing_submenu_`. + CHECK(weak_this); // Figure out if the mouse is under the menu; if so, remember the mouse // location so we can ignore the first mouse move event(s) with that