[cr148] Fixes dangling pointer crashes in browser tests.

Memory was released on:
Task trace:
        brave_browser_tests!component_updater::CrxUpdateService::~CrxUpdateService [0x7ff6b1eacd13+23] (src\components\component_updater\component_updater_service.cc:137)
        brave_browser_tests!BrowserProcessImpl::~BrowserProcessImpl [0x7ff6ad3e5c80+380] (src\chrome\browser\browser_process_impl.cc:566)

Dangling reference from:
        brave_browser_tests!brave_wallet::WalletDataFilesInstaller::SetDelegate [0x7ff6ae2790b6+76] (src\brave\components\brave_wallet\browser\wallet_data_files_installer.cc:174)
        brave_browser_tests!BraveBrowserProcessImpl::StartBraveServices [0x7ff6ad3802e9+f9] (src\brave\browser\brave_browser_process_impl.cc:300)

Renames WalletDataFilesInstaller::ResetForTesting to Reset and adds a
call to it in BraveBrowserProcessImpl::StartTearDown.

Chromium change:
https://source.chromium.org/chromium/chromium/src/+/95eade2523f5c839c531717a7a0ff5eccbced8d2

commit 95eade2523f5c839c531717a7a0ff5eccbced8d2
Author: Sylvain Defresne <sdefresne@chromium.org>
Date:   Thu Apr 2 09:20:00 2026 -0700

    [base] Change default value of RawPtrTraits of ScopedObservation<...>

    After all dangling ScopedObservation<...> have been identified, it is
    possible to change the default value of RawPtrTraits to kEmpty (i.e.
    not dangling).

    Bug: 493572976
    Change-Id: I18be9cd98e88d82a75c84a87cdd58440c71807b9
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7720939
    Reviewed-by: Daniel Cheng <dcheng@chromium.org>
    Commit-Queue: Daniel Cheng <dcheng@chromium.org>
    Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1609274}
This commit is contained in:
Max Karolinskiy
2026-04-27 12:01:00 +01:00
committed by Claudio DeSouza
parent a0f8dd4027
commit 3944a99f39
6 changed files with 13 additions and 5 deletions
+8
View File
@@ -236,6 +236,14 @@ void BraveBrowserProcessImpl::StartTearDown() {
}
#if BUILDFLAG(ENABLE_BRAVE_AI_CHAT_AGENT_PROFILE)
ai_chat_agent_profile_manager_.reset();
#endif
#if BUILDFLAG(ENABLE_BRAVE_WALLET)
// Reset WalletDataFilesInstaller to prevent dangling pointer to
// CrxUpdateService. WalletDataFilesInstaller instance is a static
// base::NoDestructor<> and makes use of
// component_updater::ComponentUpdateService::Observer, so it needs to be
// reset before the CrxUpdateService is destroyed.
brave_wallet::WalletDataFilesInstaller::GetInstance().Reset();
#endif
// Reset BraveOriginPolicyManager to prevent dangling pointer to local_state_
brave_origin::BraveOriginPolicyManager::GetInstance()->Shutdown();
@@ -119,7 +119,7 @@ class JSEthereumProviderBrowserTest : public InProcessBrowserTest {
// We need to prevent the wallet creation from being stuck waiting to
// download a restrictions list that doesn't exist.
brave_wallet::WalletDataFilesInstaller::GetInstance().ResetForTesting();
brave_wallet::WalletDataFilesInstaller::GetInstance().Reset();
}
content::WebContents* web_contents() {
@@ -143,7 +143,7 @@ class WalletPanelUIBrowserTest : public InProcessBrowserTest {
// We need to prevent the wallet creation from being stuck waiting to
// download a restrictions list that doesn't exist.
WalletDataFilesInstaller::GetInstance().ResetForTesting();
WalletDataFilesInstaller::GetInstance().Reset();
brave_wallet_service()->keyring_service()->CreateWallet("password_123",
base::DoNothing());
@@ -238,7 +238,7 @@ void WalletDataFilesInstaller::OnEvent(
}
}
void WalletDataFilesInstaller::ResetForTesting() {
void WalletDataFilesInstaller::Reset() {
component_updater_observation_.Reset();
delegate_.reset();
registered_ = false;
@@ -54,7 +54,7 @@ class WalletDataFilesInstaller
// component_updater::ComponentUpdateService::Observer:
void OnEvent(const update_client::CrxUpdateItem& item) override;
void ResetForTesting();
void Reset();
private:
friend base::NoDestructor<WalletDataFilesInstaller>;
@@ -117,7 +117,7 @@ class WalletDataFilesInstallerUnitTest : public testing::Test {
}
void TearDown() override {
installer().ResetForTesting();
installer().Reset();
registry()->ResetForTesting();
}