From 8b523cf88a5030aa2716a644c1574dc73ccd83a3 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 4 Sep 2019 13:42:23 -0700 Subject: [PATCH] fix: ensure modeL_ exists before calling delegate methods (#20111) This is a speculative fix for a crash we are seeing in `menuDidClose`. We can't repro the crash but the traces have it happening in this method and just by reading through the impl the only part that jumps out as Might Crash is this `model_` call. Other methods in the menu controller check `model_` before using it so it probably makes sense to do that here as well. --- shell/browser/ui/cocoa/atom_menu_controller.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/browser/ui/cocoa/atom_menu_controller.mm b/shell/browser/ui/cocoa/atom_menu_controller.mm index bfbc5e3035..b7da7e7666 100644 --- a/shell/browser/ui/cocoa/atom_menu_controller.mm +++ b/shell/browser/ui/cocoa/atom_menu_controller.mm @@ -375,7 +375,8 @@ static base::scoped_nsobject recentDocumentsMenuSwap_; - (void)menuDidClose:(NSMenu*)menu { if (isMenuOpen_) { isMenuOpen_ = NO; - model_->MenuWillClose(); + if (model_) + model_->MenuWillClose(); // Post async task so that itemSelected runs before the close callback // deletes the controller from the map which deallocates it if (!closeCallback.is_null()) {