Bug 1532636 - nsPrefBranch should unregister itself as observer when shutting down, r=gsvelto
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 06 Mar 2019 08:55:23 +0000
changeset 462553 35f5d2d519eb442c74d883fc88fcbc0e10b6af5b
parent 462552 2c2584c8276f00c69f24e2a3353aaf642c144f05
child 462554 8c835f11c111c813ff3471882c636949a1255453
push id79719
push useramarchesini@mozilla.com
push dateWed, 06 Mar 2019 08:57:02 +0000
treeherderautoland@8c835f11c111 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1532636
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532636 - nsPrefBranch should unregister itself as observer when shutting down, r=gsvelto Differential Revision: https://phabricator.services.mozilla.com/D22086
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -2062,22 +2062,16 @@ nsPrefBranch::nsPrefBranch(const char* a
     // Add weakly so we don't have to clean up at shutdown.
     observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
     --mRefCnt;
   }
 }
 
 nsPrefBranch::~nsPrefBranch() {
   FreeObserverList();
-
-  nsCOMPtr<nsIObserverService> observerService =
-      mozilla::services::GetObserverService();
-  if (observerService) {
-    observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
-  }
 }
 
 NS_IMPL_ISUPPORTS(nsPrefBranch, nsIPrefBranch, nsIObserver,
                   nsISupportsWeakReference)
 
 NS_IMETHODIMP
 nsPrefBranch::GetRoot(nsACString& aRoot) {
   aRoot = mPrefRoot;
@@ -2775,16 +2769,23 @@ void nsPrefBranch::FreeObserverList() {
   mFreeingObserverList = true;
   for (auto iter = mObservers.Iter(); !iter.Done(); iter.Next()) {
     nsAutoPtr<PrefCallback>& callback = iter.Data();
     Preferences::UnregisterCallback(nsPrefBranch::NotifyObserver,
                                     callback->GetDomain(), callback,
                                     Preferences::PrefixMatch);
     iter.Remove();
   }
+
+  nsCOMPtr<nsIObserverService> observerService =
+      mozilla::services::GetObserverService();
+  if (observerService) {
+    observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
+  }
+
   mFreeingObserverList = false;
 }
 
 void nsPrefBranch::RemoveExpiredCallback(PrefCallback* aCallback) {
   MOZ_ASSERT(aCallback->IsExpired());
   mObservers.Remove(aCallback);
 }