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 520439 35f5d2d519eb442c74d883fc88fcbc0e10b6af5b
parent 520438 2c2584c8276f00c69f24e2a3353aaf642c144f05
child 520440 8c835f11c111c813ff3471882c636949a1255453
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [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);
 }