Bug 1209124 - Bail out of nsStyleSet::GatherRuleProcessors and PresShell::Observe if we're called during/after shutdown. r=dbaron
authorCameron McCormack <cam@mcc.id.au>
Tue, 29 Sep 2015 12:16:04 +1000
changeset 264877 d22d047dd978a621b6ed4202c3676078b079dd54
parent 264876 9c445ab04fc314f11f9cfbf8bc2e8d3e53ee4e5f
child 264878 37c89ad82a13066287f8fed5711a0442b9b391aa
push id65770
push usercmccormack@mozilla.com
push dateTue, 29 Sep 2015 04:01:15 +0000
treeherdermozilla-inbound@d22d047dd978 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1209124
milestone44.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 1209124 - Bail out of nsStyleSet::GatherRuleProcessors and PresShell::Observe if we're called during/after shutdown. r=dbaron
layout/base/nsPresShell.cpp
layout/style/nsStyleSet.cpp
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -9386,16 +9386,21 @@ WalkFramesThroughPlaceholders(nsPresCont
 }
 #endif
 
 NS_IMETHODIMP
 PresShell::Observe(nsISupports* aSubject,
                    const char* aTopic,
                    const char16_t* aData)
 {
+  if (mIsDestroying) {
+    NS_WARNING("our observers should have been unregistered by now");
+    return NS_OK;
+  }
+
 #ifdef MOZ_XUL
   if (!nsCRT::strcmp(aTopic, "chrome-flush-skin-caches")) {
     nsIFrame *rootFrame = mFrameConstructor->GetRootFrame();
     // Need to null-check because "chrome-flush-skin-caches" can happen
     // at interesting times during startup.
     if (rootFrame) {
       NS_ASSERTION(mViewManager, "View manager must exist");
 
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -384,16 +384,18 @@ SortStyleSheetsByScope(nsTArray<CSSStyle
   for (uint32_t i = 0; i < n; i++) {
     aSheets[i] = sheets[i].mSheet;
   }
 }
 
 nsresult
 nsStyleSet::GatherRuleProcessors(sheetType aType)
 {
+  NS_ENSURE_FALSE(mInShutdown, NS_ERROR_FAILURE);
+
   // We might be in GatherRuleProcessors because we are dropping a sheet,
   // resulting in an nsCSSSelector being destroyed.  Tell the
   // RestyleManager for each document we're used in so that they can
   // drop any nsCSSSelector pointers (used for eRestyle_SomeDescendants)
   // in their mPendingRestyles.
   if (IsCSSSheetType(aType)) {
     ClearSelectors();
   }