Bug 1422634: Avoid sheet notifications to dereference a null restyle manager. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 04 Dec 2017 11:22:33 +0100
changeset 706893 90188dba461aa77e6be00cd8a9efec360d45ecc1
parent 706878 3515bb71d20ee4a2ad392178db966a8ff65157d6
child 742780 1a41b66acfbbde54321cf1bbb2a67cb14b7c1f7f
push id91940
push userbmo:emilio@crisal.io
push dateMon, 04 Dec 2017 10:38:45 +0000
reviewersheycam
bugs1422634
milestone59.0a1
Bug 1422634: Avoid sheet notifications to dereference a null restyle manager. r?heycam MozReview-Commit-ID: 2BLUCEqnRDG
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -174,16 +174,22 @@ ServoStyleSet::Init(nsPresContext* aPres
 void
 ServoStyleSet::Shutdown()
 {
   // Make sure we drop our cached style contexts before the presshell arena
   // starts going away.
   ClearNonInheritingStyleContexts();
   mRawSet = nullptr;
   mStyleRuleMap = nullptr;
+
+  // Also drop the reference to the pres context to avoid notifications from our
+  // stylesheets to dereference a null restyle manager, see bug 1422634.
+  //
+  // We should really fix bug 154199...
+  mPresContext = nullptr;
 }
 
 void
 ServoStyleSet::InvalidateStyleForCSSRuleChanges()
 {
   MOZ_ASSERT(StylistNeedsUpdate());
   mPresContext->RestyleManager()->AsServo()->PostRestyleEventForCSSRuleChanges();
 }
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -595,17 +595,18 @@ private:
                          ServoStyleSheet* aSheet,
                          ServoStyleSheet* aBeforeSheet);
 
   void RemoveSheetOfType(SheetType aType,
                          ServoStyleSheet* aSheet);
 
   const Kind mKind;
 
-  // Nullptr if this is an XBL style set.
+  // Nullptr if this is an XBL style set, or if we've been already detached from
+  // our shell.
   nsPresContext* MOZ_NON_OWNING_REF mPresContext = nullptr;
 
   // Because XBL style set could be used by multiple PresContext, we need to
   // store the last PresContext pointer which uses this XBL styleset for
   // computing medium rule changes.
   void* MOZ_NON_OWNING_REF mLastPresContextUsesXBLStyleSet = nullptr;
 
   UniquePtr<RawServoStyleSet> mRawSet;