Bug 1606091 - make sure to remove folder listener before adding another one, to avoid crash [@ nsMsgMailSession::AddFolderListener(nsIFolderListener *,unsigned int)]. r=benc DONTBUILD
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 24 Feb 2020 11:59:49 +0200
changeset 37419 bb6db0e80a06f4550e6bc9f1c80b3faf15763340
parent 37418 a144a25e51915e9d91761340c0e1b62969769d6a
child 37420 2a7bb79c9728de95188518f89c2b83e268e3bdaa
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenc
bugs1606091
Bug 1606091 - make sure to remove folder listener before adding another one, to avoid crash [@ nsMsgMailSession::AddFolderListener(nsIFolderListener *,unsigned int)]. r=benc DONTBUILD
mailnews/base/src/nsMessenger.cpp
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -218,16 +218,22 @@ NS_IMPL_ISUPPORTS(nsMessenger, nsIMessen
 NS_IMETHODIMP nsMessenger::SetWindow(mozIDOMWindowProxy *aWin,
                                      nsIMsgWindow *aMsgWindow) {
   nsresult rv;
 
   nsCOMPtr<nsIMsgMailSession> mailSession =
       do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // Remove the folder listener if we added it, i.e. if mWindow is non-null.
+  if (mWindow) {
+    rv = mailSession->RemoveFolderListener(this);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
   if (aWin) {
     mMsgWindow = aMsgWindow;
     mWindow = aWin;
 
     rv = mailSession->AddFolderListener(this, nsIFolderListener::removed);
     NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ENSURE_TRUE(aWin, NS_ERROR_FAILURE);
@@ -250,22 +256,16 @@ NS_IMETHODIMP nsMessenger::SetWindow(moz
         aMsgWindow->GetTransactionManager(getter_AddRefs(mTxnMgr));
     }
 
     // We don't always have a message pane, like in the addressbook
     // so if we don't have a docshell, use the one for the app window.
     // we do this so OpenURL() will work.
     if (!mDocShell) mDocShell = rootShell;
   } else {
-    // Remove the folder listener if we added it, i.e. if mWindow is non-null
-    if (mWindow) {
-      rv = mailSession->RemoveFolderListener(this);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-
     mWindow = nullptr;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMessenger::SetDisplayCharset(const nsACString &aCharset) {
   // libmime always converts to UTF-8 (both HTML and XML)