Fix leaked raw_ptr/raw_ref in BraveOriginService#34275
Merged
bbondy merged 1 commit intobrave:masterfrom Mar 1, 2026
Merged
Conversation
Override KeyedService::Shutdown() to clean up raw_ptr members and invalidate weak pointers before the service is destroyed. Without this, the defaulted destructor detects dangling raw_ptr references to PrefService and PolicyService objects that are already freed during the profile teardown sequence. Resolves brave/brave-browser#52757
f40cfd4 to
7c5993b
Compare
Collaborator
Author
|
👋 Friendly reminder: This PR has been waiting for review for over 24 hours. @atuchin-m When you have a moment, could you please take a look? Thank you! (I was asked to send reminders for PRs waiting more than a day) |
atuchin-m
approved these changes
Mar 1, 2026
Collaborator
|
@bbondy Does it make sense to uplift it? It's not a test-only issue. |
Member
|
Probably not worth uplifting. It's disabled via a flag too |
Collaborator
|
Released in v1.89.89 |
bbondy
pushed a commit
that referenced
this pull request
Mar 2, 2026
Override KeyedService::Shutdown() to clean up raw_ptr members and invalidate weak pointers before the service is destroyed. Without this, the defaulted destructor detects dangling raw_ptr references to PrefService and PolicyService objects that are already freed during the profile teardown sequence. Resolves brave/brave-browser#52757
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Override
KeyedService::Shutdown()inBraveOriginServiceto prevent danglingraw_ptrreferences detected at test teardown.Resolves brave/brave-browser#52757
Root Cause
BraveOriginServicestoresraw_ptrmembers toPrefServiceandPolicyServiceobjects that are destroyed during the profile teardown sequence before the service's destructor runs. With the defaulted destructor, theseraw_ptrmembers detect dangling references when PartitionAlloc checks them at destruction time, causing a fatal CHECK failure.Fix
Override
KeyedService::Shutdown()to:raw_ptrmembers (local_state_,profile_prefs_,profile_policy_service_,browser_policy_service_)This follows the established Chromium pattern for
KeyedServicecleanup (CSM-016, CSM-017).Test Plan