Skip to content

Commit

Permalink
fix: dangling pointer warning when updating menus (electron#38643)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckerr authored Jun 8, 2023
1 parent 95d6a93 commit 9d8da78
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions shell/browser/api/electron_api_base_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,15 @@ 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) {
RemoveMenu();
} else {
window_->SetMenu(menu->model());
}

menu_.Reset(isolate, menu.ToV8());
} else if (value->IsNull()) {
RemoveMenu();
} else {
Expand Down

0 comments on commit 9d8da78

Please sign in to comment.