Bug 610690 - Crash when printing many documents successively [@ nsCOMPtr_base::assign_from_qi | nsDocShell::SetTreeOwner ], r=mats, a=benjamin
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 10 Nov 2010 23:15:21 +0200
changeset 57279 8ae502fb1c5bc4a20c5e411f855e33c75cb732bd
parent 57278 6adc19c7a1e4dddceea6b5e72dac1fd3d41ed38a
child 57280 f4dcfa39a3551782cf1382f7ce4e975057dce89e
push idunknown
push userunknown
push dateunknown
reviewersmats, benjamin
bugs610690
milestone2.0b8pre
Bug 610690 - Crash when printing many documents successively [@ nsCOMPtr_base::assign_from_qi | nsDocShell::SetTreeOwner ], r=mats, a=benjamin
layout/printing/nsPrintObject.cpp
layout/printing/nsPrintObject.h
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -38,17 +38,16 @@
 #include "nsPrintObject.h"
 #include "nsIContentViewer.h"
 #include "nsIDOMDocument.h"
 #include "nsContentUtils.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsGkAtoms.h"
 #include "nsComponentManagerUtils.h"
-#include "nsIDocShellTreeOwner.h"
 #include "nsIDocShellTreeItem.h"
 
 //---------------------------------------------------
 //-- nsPrintObject Class Impl
 //---------------------------------------------------
 nsPrintObject::nsPrintObject() :
   mContent(nsnull), mFrameType(eFrame), mParent(nsnull),
   mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE),
@@ -61,39 +60,40 @@ nsPrintObject::nsPrintObject() :
 nsPrintObject::~nsPrintObject()
 {
   for (PRUint32 i=0;i<mKids.Length();i++) {
     nsPrintObject* po = mKids[i];
     delete po;
   }
 
   DestroyPresentation();
+  mDocShell = nsnull;
+  mTreeOwner = nsnull; // mTreeOwner must be released after mDocShell; 
 }
 
 //------------------------------------------------------------------
-// Resets PO by destroying the presentation
 nsresult 
 nsPrintObject::Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc,
                     PRBool aPrintPreview)
 {
   mPrintPreview = aPrintPreview;
 
   if (mPrintPreview || mParent) {
     mDocShell = aDocShell;
   } else {
-    nsCOMPtr<nsIDocShellTreeOwner> owner = do_GetInterface(aDocShell);
+    mTreeOwner = do_GetInterface(aDocShell);
     nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(aDocShell);
     PRInt32 itemType = 0;
     item->GetItemType(&itemType);
     // Create a container docshell for printing.
     mDocShell = do_CreateInstance("@mozilla.org/docshell;1");
     NS_ENSURE_TRUE(mDocShell, NS_ERROR_OUT_OF_MEMORY);
     nsCOMPtr<nsIDocShellTreeItem> newItem = do_QueryInterface(mDocShell);
     newItem->SetItemType(itemType);
-    newItem->SetTreeOwner(owner);
+    newItem->SetTreeOwner(mTreeOwner);
   }
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMDocument> dummy = do_GetInterface(mDocShell);
   nsCOMPtr<nsIContentViewer> viewer;
   mDocShell->GetContentViewer(getter_AddRefs(viewer));
   NS_ENSURE_STATE(viewer);
 
--- a/layout/printing/nsPrintObject.h
+++ b/layout/printing/nsPrintObject.h
@@ -40,16 +40,17 @@
 // Interfaces
 #include "nsCOMPtr.h"
 #include "nsIContent.h"
 #include "nsIPresShell.h"
 #include "nsStyleSet.h"
 #include "nsIViewManager.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
+#include "nsIDocShellTreeOwner.h"
 
 class nsPresContext;
 
 // nsPrintObject Document Type
 enum PrintObjectType  {eDoc = 0, eFrame = 1, eIFrame = 2, eFrameSet = 3};
 
 //---------------------------------------------------
 //-- nsPrintObject Class
@@ -65,16 +66,17 @@ public:
   nsresult Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc,
                 PRBool aPrintPreview);
 
   PRBool IsPrintable()  { return !mDontPrint; }
   void   DestroyPresentation();
 
   // Data Members
   nsCOMPtr<nsIDocShell>    mDocShell;
+  nsCOMPtr<nsIDocShellTreeOwner> mTreeOwner;
   nsCOMPtr<nsIDocument>    mDocument;
 
   nsRefPtr<nsPresContext>  mPresContext;
   nsCOMPtr<nsIPresShell>   mPresShell;
   nsCOMPtr<nsIViewManager> mViewManager;
 
   nsCOMPtr<nsIContent>     mContent;
   PrintObjectType  mFrameType;