From 8fec7adfa6763d7fb6ec966431786f0fc841e8dd Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 18:05:13 -0500 Subject: [PATCH] fix: gin_helper::Promise in GPUInfoManager must be destroyed before destroying Node/V8 (#46471) * fix: gin_helper::Promise in GPUInfoManager must be destroyed before destroying Node/V8 Co-authored-by: Yang Liu * fix: use CleanedUpAtExit to control the lifetime of GPUInfoManager Co-authored-by: Yang Liu --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Yang Liu --- shell/browser/api/gpuinfo_manager.cc | 4 +++- shell/browser/api/gpuinfo_manager.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/shell/browser/api/gpuinfo_manager.cc b/shell/browser/api/gpuinfo_manager.cc index 4a2f4f30e4..b68d7e27e6 100644 --- a/shell/browser/api/gpuinfo_manager.cc +++ b/shell/browser/api/gpuinfo_manager.cc @@ -17,7 +17,9 @@ namespace electron { GPUInfoManager* GPUInfoManager::GetInstance() { - return base::Singleton::get(); + // will be deleted by CleanedUpAtExit::DoCleanup + static GPUInfoManager* instance = new GPUInfoManager(); + return instance; } GPUInfoManager::GPUInfoManager() diff --git a/shell/browser/api/gpuinfo_manager.h b/shell/browser/api/gpuinfo_manager.h index 3ee3947510..b2f5cae518 100644 --- a/shell/browser/api/gpuinfo_manager.h +++ b/shell/browser/api/gpuinfo_manager.h @@ -11,6 +11,7 @@ #include "content/browser/gpu/gpu_data_manager_impl.h" // nogncheck #include "content/public/browser/gpu_data_manager.h" #include "content/public/browser/gpu_data_manager_observer.h" +#include "shell/common/gin_helper/cleaned_up_at_exit.h" namespace gin_helper { template @@ -20,7 +21,8 @@ class Promise; namespace electron { // GPUInfoManager is a singleton used to manage and fetch GPUInfo -class GPUInfoManager : private content::GpuDataManagerObserver { +class GPUInfoManager : private content::GpuDataManagerObserver, + public gin_helper::CleanedUpAtExit { public: static GPUInfoManager* GetInstance();