From 7cfd4b2cedb1b6b4e5221bef336dc4ac55b49451 Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Wed, 13 Nov 2024 10:41:40 +1300 Subject: [PATCH] Bug 1930787 - Stop IMAP incoming servers trying to do things after shutting down. r=gds Differential Revision: https://phabricator.services.mozilla.com/D228753 --HG-- extra : rebase_source : 2c360df0590c6a1719a1d98af847370deae0605e extra : amend_source : e3dc1a61ef60f206679418826b4f523781b1dfbf --- mailnews/base/src/nsMsgIncomingServer.cpp | 4 +++- mailnews/base/src/nsMsgIncomingServer.h | 1 + mailnews/imap/src/nsImapIncomingServer.cpp | 1 + mailnews/imap/src/nsImapProtocol.cpp | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mailnews/base/src/nsMsgIncomingServer.cpp b/mailnews/base/src/nsMsgIncomingServer.cpp index 279b26b37d..4f5f634e29 100644 --- a/mailnews/base/src/nsMsgIncomingServer.cpp +++ b/mailnews/base/src/nsMsgIncomingServer.cpp @@ -45,7 +45,8 @@ #define PORT_NOT_SET -1 nsMsgIncomingServer::nsMsgIncomingServer() - : m_rootFolder(nullptr), + : m_hasShutDown(false), + m_rootFolder(nullptr), m_downloadedHdrs(50), m_numMsgsDownloaded(0), m_biffState(nsIMsgFolder::nsMsgBiffState_Unknown), @@ -295,6 +296,7 @@ NS_IMETHODIMP nsMsgIncomingServer::WriteToFolderCache( NS_IMETHODIMP nsMsgIncomingServer::Shutdown() { nsresult rv = CloseCachedConnections(); + m_hasShutDown = true; mFilterPlugin = nullptr; NS_ENSURE_SUCCESS(rv, rv); diff --git a/mailnews/base/src/nsMsgIncomingServer.h b/mailnews/base/src/nsMsgIncomingServer.h index 0fb4432262..b83c898cba 100644 --- a/mailnews/base/src/nsMsgIncomingServer.h +++ b/mailnews/base/src/nsMsgIncomingServer.h @@ -46,6 +46,7 @@ class nsMsgIncomingServer : public nsIMsgIncomingServer, protected: virtual ~nsMsgIncomingServer(); nsCString m_serverKey; + bool m_hasShutDown; // Sets m_password, if password found. Can return NS_ERROR_ABORT if the // user cancels the master password dialog. diff --git a/mailnews/imap/src/nsImapIncomingServer.cpp b/mailnews/imap/src/nsImapIncomingServer.cpp index b09e3a8958..6fc6ac813b 100644 --- a/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mailnews/imap/src/nsImapIncomingServer.cpp @@ -474,6 +474,7 @@ nsImapIncomingServer::RetryUrl(nsIImapUrl* aImapUrl, NS_IMETHODIMP nsImapIncomingServer::LoadNextQueuedUrl(nsIImapProtocol* aProtocol, bool* aResult) { + if (m_hasShutDown) return NS_ERROR_FAILURE; if (WeAreOffline()) return NS_MSG_ERROR_OFFLINE; nsresult rv = NS_OK; diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index a3d5755352..aa18929b78 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -2346,6 +2346,9 @@ NS_IMETHODIMP nsImapProtocol::LoadImapUrl(nsIURI* aURL, m_imapMailFolderSink = nullptr; rv = SetupWithUrl(aURL, aConsumer); m_lastActiveTime = PR_Now(); + if (NS_FAILED(rv)) { + TellThreadToDie(true); + } } return rv; }