Skip to content

Commit

Permalink
Merge pull request #25943 from brave/fix-adblock-pref-service-danglin…
Browse files Browse the repository at this point in the history
…g-access

[DanglingPtr] Fix `AdBlockPrefService` dangling access
  • Loading branch information
bsclifton authored Oct 11, 2024
2 parents 6c49eae + 289292c commit 1dc32e1
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1dc32e1

Please sign in to comment.