Fix leaked raw_ptr/raw_ref in BraveOriginService (#34275)
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 https://github.com/brave/brave-browser/issues/52757
This commit is contained in:
@@ -73,6 +73,15 @@ BraveOriginService::BraveOriginService(
|
||||
|
||||
BraveOriginService::~BraveOriginService() = default;
|
||||
|
||||
void BraveOriginService::Shutdown() {
|
||||
weak_ptr_factory_.InvalidateWeakPtrs();
|
||||
skus_service_.reset();
|
||||
local_state_ = nullptr;
|
||||
profile_prefs_ = nullptr;
|
||||
profile_policy_service_ = nullptr;
|
||||
browser_policy_service_ = nullptr;
|
||||
}
|
||||
|
||||
bool BraveOriginService::IsPolicyControlledByBraveOrigin(
|
||||
std::string_view policy_key) const {
|
||||
if (!IsBraveOriginEnabled()) {
|
||||
|
||||
@@ -44,6 +44,9 @@ class BraveOriginService : public KeyedService {
|
||||
SkusServiceGetter skus_service_getter);
|
||||
~BraveOriginService() override;
|
||||
|
||||
// KeyedService:
|
||||
void Shutdown() override;
|
||||
|
||||
// Check if a policy is controlled by BraveOrigin
|
||||
bool IsPolicyControlledByBraveOrigin(std::string_view policy_key) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user