Bug 830236 - Add re-entrancy protection in a few places to avoid destroying things twice. r=cam a=lsblakk
authorMats Palmgren <matspal@gmail.com>
Tue, 22 Jan 2013 16:06:27 +0100
changeset 127248 2510eb4709c5b13930b5ca973acb7166c0a6d027
parent 127247 d426b31dcadb9bf1e434ad6f6a035c93984e62cc
child 127249 5582b6d395e92a546e345047125ef7332cdebeb2
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscam, lsblakk
bugs830236
milestone20.0a2
Bug 830236 - Add re-entrancy protection in a few places to avoid destroying things twice. r=cam a=lsblakk
layout/base/nsDocumentViewer.cpp
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
layout/printing/nsPrintObject.cpp
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -4258,21 +4258,22 @@ nsDocumentViewer::ReturnToGalleyPresenta
 //   up when an error occurred during the start up printing 
 //   and print preview
 //
 void
 nsDocumentViewer::OnDonePrinting() 
 {
 #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
   if (mPrintEngine) {
+    nsRefPtr<nsPrintEngine> pe = mPrintEngine;
+    mPrintEngine = nullptr;
     if (GetIsPrintPreview()) {
-      mPrintEngine->DestroyPrintingData();
+      pe->DestroyPrintingData();
     } else {
-      mPrintEngine->Destroy();
-      mPrintEngine = nullptr;
+      pe->Destroy();
     }
 
     // We are done printing, now cleanup 
     if (mDeferredWindowClose) {
       mDeferredWindowClose = false;
       nsCOMPtr<nsISupports> container = do_QueryReferent(mContainer);
       nsCOMPtr<nsIDOMWindow> win = do_GetInterface(container);
       if (win)
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -233,29 +233,35 @@ nsPrintEngine::nsPrintEngine() :
   mScreenDPI(115.0f),
   mPrt(nullptr),
   mPagePrintTimer(nullptr),
   mPageSeqFrame(nullptr),
   mPrtPreview(nullptr),
   mOldPrtPreview(nullptr),
   mDebugFile(nullptr),
   mLoadCounter(0),
-  mDidLoadDataForPrinting(false)
+  mDidLoadDataForPrinting(false),
+  mIsDestroying(false)
 {
 }
 
 //-------------------------------------------------------
 nsPrintEngine::~nsPrintEngine()
 {
   Destroy(); // for insurance
 }
 
 //-------------------------------------------------------
 void nsPrintEngine::Destroy()
 {
+  if (mIsDestroying) {
+    return;
+  }
+  mIsDestroying = true;
+
   if (mPrt) {
     delete mPrt;
     mPrt = nullptr;
   }
 
 #ifdef NS_PRINT_PREVIEW
   if (mPrtPreview) {
     delete mPrtPreview;
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintEngine.h
@@ -275,16 +275,17 @@ protected:
   nsPrintData*            mOldPrtPreview;
 
   nsCOMPtr<nsIDocument>   mDocument;
 
   FILE* mDebugFile;
 
   int32_t mLoadCounter;
   bool mDidLoadDataForPrinting;
+  bool mIsDestroying;
 
   nsresult AfterNetworkPrint(bool aHandleError);
 
   nsresult SetRootView(nsPrintObject* aPO,
                        bool& aDoReturn,
                        bool& aDocumentIsTopLevel,
                        nsSize& aAdjSize);
   nsView* GetParentViewForRoot();
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -108,15 +108,16 @@ nsPrintObject::DestroyPresentation()
 #ifdef MOZ_CRASHREPORTER
     if (mPresShell->GetPresContext() && !mPresShell->GetPresContext()->GetPresShell()) {
       NS_ASSERTION(false, "about to destroy print object's PresShell when its pres context no longer has it");
       CrashReporter::AppendAppNotesToCrashReport(NS_LITERAL_CSTRING("about to destroy print object's PresShell when its pres context no longer has it\n"));
     }
 #endif
     mPresShell->EndObservingDocument();
     nsAutoScriptBlocker scriptBlocker;
-    mPresShell->Destroy();
+    nsCOMPtr<nsIPresShell> shell = mPresShell;
+    mPresShell = nullptr;
+    shell->Destroy();
   }
   mPresContext = nullptr;
-  mPresShell   = nullptr;
   mViewManager = nullptr;
 }