diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 900248c3391f..9d64c737a66f 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -1480,7 +1480,10 @@ RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint, NS_UpdateHint(mRebuildAllExtraHint, aExtraHint); mRebuildAllRestyleHint |= aRestyleHint; - nsIPresShell* presShell = mPresContext->GetPresShell(); + // Processing the style changes could cause a flush that propagates to + // the parent frame and thus destroys the pres shell, so we must hold + // a reference. + nsCOMPtr presShell = mPresContext->GetPresShell(); if (!presShell || !presShell->GetRootFrame()) { mDoRebuildAllStyleData = false; return; @@ -1489,10 +1492,6 @@ RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint, // Make sure that the viewmanager will outlive the presshell nsRefPtr vm = presShell->GetViewManager(); - // Processing the style changes could cause a flush that propagates to - // the parent frame and thus destroys the pres shell. - nsCOMPtr kungFuDeathGrip(presShell); - // We may reconstruct frames below and hence process anything that is in the // tree. We don't want to get notified to process those items again after. presShell->GetDocument()->FlushPendingNotifications(Flush_ContentAndNotify);