Bug 1382118 - Make nsPrintEngine::AfterNetworkPrint() do nothing if mPtr is nullptr r=dholbert
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 22 Jul 2017 00:43:38 +0900
changeset 421815 aebaa2a545ba19f6667859b0afaa237364f61863
parent 421814 ef4d1461791e38d3730fc8e43aee0e871e83333c
child 421816 f98953cb41ef6eecaa7c2d348974b4c584e37618
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1382118
milestone56.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 1382118 - Make nsPrintEngine::AfterNetworkPrint() do nothing if mPtr is nullptr r=dholbert According to the crash reports, nsPrintEngine::AfterNetworkPrint() may be called after nsPrintEngine::Destroy() is called. In this case, the method should do nothing because it's already been destroyed. MozReview-Commit-ID: IwY9fR1OUwU
layout/printing/nsPrintEngine.cpp
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -1943,16 +1943,28 @@ nsPrintEngine::InitPrintDocConstruction(
     AfterNetworkPrint(aHandleError);
   }
   return rv;
 }
 
 nsresult
 nsPrintEngine::AfterNetworkPrint(bool aHandleError)
 {
+  // If Destroy() has already been called, mPtr is nullptr.  Then, the instance
+  // needs to do nothing anymore in this method.
+  // Note: it shouldn't be possible for mPrt->mPrintObject to be null; we
+  // just check it for good measure, as we check its owner.
+  // Note: it shouldn't be possible for mPrt->mPrintObject->mDocShell to be
+  // null; we just check it for good measure, as we check its owner.
+  if (!mPrt ||
+      NS_WARN_IF(!mPrt->mPrintObject) ||
+      NS_WARN_IF(!mPrt->mPrintObject->mDocShell)) {
+    return NS_ERROR_FAILURE;
+  }
+
   nsCOMPtr<nsIWebProgress> webProgress = do_QueryInterface(mPrt->mPrintObject->mDocShell);
 
   webProgress->RemoveProgressListener(
     static_cast<nsIWebProgressListener*>(this));
 
   nsresult rv;
   if (mIsDoingPrinting) {
     rv = DocumentReadyForPrinting();