Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(908)

Unified Diff: ui/views/controls/menu/menu_controller.cc

Issue 2636293002: Fix MenuController Heap-use-after-free (Closed)
Patch Set: Typo in comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_controller.cc
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index 95dd4f9a9de9b687b422ecd8e10584fe9590fc8b..e7c02a01ef8418f8065747aac596e626cb3d436e 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -2576,6 +2576,9 @@ void MenuController::ExitAsyncRun() {
// ExitMenuRun unwinds nested delegates
internal::MenuControllerDelegate* delegate = delegate_;
MenuItemView* result = ExitMenuRun();
+ // MenuController may have been deleted when releasing ViewsDelegate ref.
+ if (!GetActiveInstance())
+ return;
delegate->OnMenuClosed(internal::MenuControllerDelegate::NOTIFY_DELEGATE,
result, accept_event_flags_);
// MenuController may have been deleted by |delegate|.
@@ -2589,6 +2592,10 @@ MenuItemView* MenuController::ExitMenuRun() {
if (async_run_ && ViewsDelegate::GetInstance())
ViewsDelegate::GetInstance()->ReleaseRef();
+ // Releasing the lock can result in Chrome shutting down, deleting this.
+ if (!GetActiveInstance())
+ return nullptr;
+
// Close any open menus.
SetSelection(nullptr, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT);
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698