From 289292c4f39b1d4f4db10f24f49870434413f3d3 Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Fri, 11 Oct 2024 06:38:30 +0100 Subject: [PATCH] [DanglingPtr] Fix `AdBlockPrefService` dangling access This is a simple destruction order type of dangling problem, as both data members involved are reset deterministically. --- .../content/browser/ad_block_pref_service.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/brave_shields/content/browser/ad_block_pref_service.cc b/components/brave_shields/content/browser/ad_block_pref_service.cc index b881b26ebd72..79a4d74a283e 100644 --- a/components/brave_shields/content/browser/ad_block_pref_service.cc +++ b/components/brave_shields/content/browser/ad_block_pref_service.cc @@ -86,15 +86,19 @@ AdBlockPrefService::GetLatestProxyConfig( void AdBlockPrefService::Shutdown() { pref_change_registrar_.reset(); - if (proxy_config_service_) { - proxy_config_service_->RemoveObserver(this); - proxy_config_service_.reset(); - } + // `pref_proxy_config_tracker_` has a reference to `proxy_config_service_`, + // therefore detach `pref_proxy_config_tracker_` first, to prevent the + // reference from dangling. if (pref_proxy_config_tracker_) { pref_proxy_config_tracker_->DetachFromPrefService(); pref_proxy_config_tracker_.reset(); } + + if (proxy_config_service_) { + proxy_config_service_->RemoveObserver(this); + proxy_config_service_.reset(); + } } void AdBlockPrefService::OnPreferenceChanged(const std::string& pref_name) {