From 3a91d1f1e18177ceadc02580722a1349c5b18357 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 21 Aug 2023 03:29:25 -0500 Subject: [PATCH] fix: dangling raw_ptr in ElectronBrowserMainParts dtor (#39539) * fix: dangling raw_ptr in ElectronBrowserMainParts dtor * fixup! fix: dangling raw_ptr in ElectronBrowserMainParts dtor Browser::WhenReady() holds a reference to JsEnv isolate so must come after --- shell/browser/electron_browser_main_parts.cc | 10 +++++----- shell/browser/electron_browser_main_parts.h | 13 +++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc index 6995be4069bb..61c0b3df0106 100644 --- a/shell/browser/electron_browser_main_parts.cc +++ b/shell/browser/electron_browser_main_parts.cc @@ -204,11 +204,11 @@ ElectronBrowserMainParts* ElectronBrowserMainParts::self_ = nullptr; ElectronBrowserMainParts::ElectronBrowserMainParts() : fake_browser_process_(std::make_unique()), - browser_(std::make_unique()), - node_bindings_( - NodeBindings::Create(NodeBindings::BrowserEnvironment::kBrowser)), - electron_bindings_( - std::make_unique(node_bindings_->uv_loop())) { + node_bindings_{ + NodeBindings::Create(NodeBindings::BrowserEnvironment::kBrowser)}, + electron_bindings_{ + std::make_unique(node_bindings_->uv_loop())}, + browser_{std::make_unique()} { DCHECK(!self_) << "Cannot have two ElectronBrowserMainParts"; self_ = this; } diff --git a/shell/browser/electron_browser_main_parts.h b/shell/browser/electron_browser_main_parts.h index 917da8626004..69f4c32cd967 100644 --- a/shell/browser/electron_browser_main_parts.h +++ b/shell/browser/electron_browser_main_parts.h @@ -157,11 +157,20 @@ class ElectronBrowserMainParts : public content::BrowserMainParts { // Before then, we just exit() without any intermediate steps. absl::optional exit_code_; - std::unique_ptr js_env_; - std::unique_ptr browser_; std::unique_ptr node_bindings_; + + // depends-on: node_bindings_ std::unique_ptr electron_bindings_; + + // depends-on: node_bindings_ + std::unique_ptr js_env_; + + // depends-on: js_env_'s isolate std::unique_ptr node_env_; + + // depends-on: js_env_'s isolate + std::unique_ptr browser_; + std::unique_ptr icon_manager_; std::unique_ptr field_trial_list_;