Bug 1063723 - Move nsMsgPrintEngine mWebBrowserPrint to function scope to avoid potential reuse crash. r+a=mkmelin
authorBen Campbell <benc@thunderbird.net>
Mon, 13 Jan 2020 12:13:57 +0200
changeset 37866 4c6fc6e8bee93f83b0f1e5347b81b00c47916077
parent 37865 4c76f8785bf216ef0f6c7428e97b6d1303a6c5fd
child 37867 1dcefcd94db905a5374efb3b7851fe3623436be4
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
bugs1063723
Bug 1063723 - Move nsMsgPrintEngine mWebBrowserPrint to function scope to avoid potential reuse crash. r+a=mkmelin
mailnews/base/src/nsMsgPrintEngine.cpp
mailnews/base/src/nsMsgPrintEngine.h
--- a/mailnews/base/src/nsMsgPrintEngine.cpp
+++ b/mailnews/base/src/nsMsgPrintEngine.cpp
@@ -524,43 +524,43 @@ void nsMsgPrintEngine::GetString(const c
 //-----------------------------------------------------------
 void nsMsgPrintEngine::PrintMsgWindow() {
   const char *kMsgKeys[] = {"PrintingMessage",  "PrintPreviewMessage",
                             "PrintingContact",  "PrintPreviewContact",
                             "PrintingAddrBook", "PrintPreviewAddrBook"};
 
   mDocShell->GetContentViewer(getter_AddRefs(mContentViewer));
   if (mContentViewer) {
-    mWebBrowserPrint = do_QueryInterface(mContentViewer);
-    if (mWebBrowserPrint) {
+    nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint =
+        do_QueryInterface(mContentViewer);
+    if (webBrowserPrint) {
       if (!mPrintSettings) {
-        mWebBrowserPrint->GetGlobalPrintSettings(
-            getter_AddRefs(mPrintSettings));
+        webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(mPrintSettings));
       }
 
       // fix for bug #118887 and bug #176016
       // don't show the actual url when printing mail messages or addressbook
       // cards. for mail, it can review the salt.  for addrbook, it's a data://
       // url, which means nothing to the end user. needs to be " " and not "" or
       // nullptr, otherwise, we'll still print the url
       mPrintSettings->SetDocURL(NS_LITERAL_STRING(" "));
 
       nsresult rv = NS_ERROR_FAILURE;
       if (mIsDoingPrintPreview) {
         if (mStartupPPObs) {
           rv = mStartupPPObs->Observe(nullptr, nullptr, nullptr);
         }
       } else {
         mPrintSettings->SetPrintSilent(mCurrentlyPrintingURI != 0);
-        rv = mWebBrowserPrint->Print(mPrintSettings,
-                                     (nsIWebProgressListener *)this);
+        rv = webBrowserPrint->Print(mPrintSettings,
+                                    (nsIWebProgressListener *)this);
       }
 
       if (NS_FAILED(rv)) {
-        mWebBrowserPrint = nullptr;
+        webBrowserPrint = nullptr;
         mContentViewer = nullptr;
         bool isPrintingCancelled = false;
         if (mPrintSettings) {
           mPrintSettings->GetIsCancelled(&isPrintingCancelled);
         }
         if (!isPrintingCancelled) {
           StartNextPrintOperation();
         } else {
--- a/mailnews/base/src/nsMsgPrintEngine.h
+++ b/mailnews/base/src/nsMsgPrintEngine.h
@@ -68,17 +68,16 @@ class nsMsgPrintEngine : public nsIMsgPr
   nsCOMPtr<mozIDOMWindowProxy> mParentWindow;
   int32_t mURICount;
   nsTArray<nsString> mURIArray;
   int32_t mCurrentlyPrintingURI;
 
   nsCOMPtr<nsIContentViewer> mContentViewer;
   nsCOMPtr<nsIStringBundle> mStringBundle;   // String bundles...
   nsCOMPtr<nsIMsgStatusFeedback> mFeedback;  // Tell the user something
-  nsCOMPtr<nsIWebBrowserPrint> mWebBrowserPrint;
   nsCOMPtr<nsIPrintSettings> mPrintSettings;
   nsCOMPtr<mozIDOMWindowProxy> mMsgDOMWin;
   bool mIsDoingPrintPreview;
   nsCOMPtr<nsIObserver> mStartupPPObs;
   int32_t mMsgInx;
 
   // Progress Dialog