Bug 1382118 - Make nsPrintEngine::AfterNetworkPrint() do nothing if mPtr is nullptr r?dholbert draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 22 Jul 2017 00:43:38 +0900
changeset 613703 b79ce0e239c057d0e85224304a348a066bfb3774
parent 613702 0f7c4b7d1e988d0398b2482708baf6fb3efc2ffd
child 638707 28425e2fefa7467d401015d63112e44dff23a8e8
push id69837
push usermasayuki@d-toybox.com
push dateSat, 22 Jul 2017 07:44:09 +0000
reviewersdholbert
bugs1382118
milestone56.0a1
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();