Browse Source

fix: dangling pointer warning when updating menus (#38643)

Charles Kerr 1 year ago
parent
commit
9d8da7839e
1 changed files with 2 additions and 2 deletions
  1. 2 2
      shell/browser/api/electron_api_base_window.cc

+ 2 - 2
shell/browser/api/electron_api_base_window.cc

@@ -706,8 +706,6 @@ void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
   v8::Local<v8::Object> object;
   if (value->IsObject() && value->ToObject(context).ToLocal(&object) &&
       gin::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
-    menu_.Reset(isolate, menu.ToV8());
-
     // We only want to update the menu if the menu has a non-zero item count,
     // or we risk crashes.
     if (menu->model()->GetItemCount() == 0) {
@@ -715,6 +713,8 @@ void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
     } else {
       window_->SetMenu(menu->model());
     }
+
+    menu_.Reset(isolate, menu.ToV8());
   } else if (value->IsNull()) {
     RemoveMenu();
   } else {