From bdbeecff2961d99ff5c9c9559b9701c725c63868 Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Tue, 28 Sep 1999 21:50:04 +0000 Subject: [PATCH] for mscott fix memory leaks of imap urls 15088 r=bienvenu, a=chofmann --- mailnews/imap/public/nsIImapMockChannel.idl | 1 + mailnews/imap/src/nsImapMailFolder.cpp | 4 ++-- mailnews/imap/src/nsImapProtocol.cpp | 19 +++++++++++++++++-- mailnews/imap/src/nsImapProtocol.h | 4 +++- mailnews/imap/src/nsImapUtils.cpp | 3 ++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/mailnews/imap/public/nsIImapMockChannel.idl b/mailnews/imap/public/nsIImapMockChannel.idl index 3def26714fa9..1a60723286fe 100644 --- a/mailnews/imap/public/nsIImapMockChannel.idl +++ b/mailnews/imap/public/nsIImapMockChannel.idl @@ -54,4 +54,5 @@ interface nsIImapMockChannel : nsIChannel void GetChannelContext(out nsISupports aChannelContext); void SetLoadGroup(in nsILoadGroup aLoadGroup); void SetURI(in nsIURI aUrl); + void Close(); }; diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index fb40899d210a..8912a0e70ec4 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -165,6 +165,7 @@ NS_IMETHODIMP nsImapMailFolder::GetPath(nsIFileSpec** aPathName) return NS_ERROR_OUT_OF_MEMORY; rv = nsImapURI2Path(kImapRootURI, mURI, *m_pathName); +// printf("constructing path %s\n", (const char *) *m_pathName); if (NS_FAILED(rv)) return rv; } rv = NS_NewFileSpecWithSpec(*m_pathName, aPathName); @@ -715,7 +716,7 @@ NS_IMETHODIMP nsImapMailFolder::UpdateSummaryTotals(PRBool force) { // could we move this into nsMsgDBFolder, or do we need to deal // with the pending imap counts? - nsresult rv; + nsresult rv = NS_OK; PRInt32 oldUnreadMessages = mNumUnreadMessages; PRInt32 oldTotalMessages = mNumTotalMessages; @@ -745,7 +746,6 @@ NS_IMETHODIMP nsImapMailFolder::UpdateSummaryTotals(PRBool force) PR_smprintf_free(oldUnreadMessagesStr); } - return NS_OK; return rv; } diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index be0b1a9204bc..58bd496a51dc 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -605,7 +605,11 @@ void nsImapProtocol::ReleaseUrlState() m_imapMiscellaneousSink = null_nsCOMPtr(); m_channelListener = null_nsCOMPtr(); m_channelContext = null_nsCOMPtr(); - m_mockChannel = null_nsCOMPtr(); + if (m_mockChannel) + { + m_mockChannel->Close(); + m_mockChannel = null_nsCOMPtr(); + } m_channelInputStream = null_nsCOMPtr(); m_channelOutputStream = null_nsCOMPtr(); @@ -666,7 +670,11 @@ NS_IMETHODIMP nsImapProtocol::Run() me->m_outputStream = null_nsCOMPtr(); me->m_channelListener = null_nsCOMPtr(); me->m_channelContext = null_nsCOMPtr(); - me->m_mockChannel = null_nsCOMPtr(); + if (me->m_mockChannel) + { + me->m_mockChannel->Close(); + me->m_mockChannel = null_nsCOMPtr(); + } me->m_channelInputStream = null_nsCOMPtr(); me->m_channelOutputStream = null_nsCOMPtr(); me->m_sinkEventQueue = null_nsCOMPtr(); @@ -6143,12 +6151,19 @@ NS_IMPL_ISUPPORTS2(nsImapMockChannel, nsIImapMockChannel, nsIChannel) nsImapMockChannel::nsImapMockChannel() { NS_INIT_REFCNT(); + m_channelContext = nsnull; } nsImapMockChannel::~nsImapMockChannel() { } +NS_IMETHODIMP nsImapMockChannel::Close() +{ + m_channelListener = null_nsCOMPtr(); + return NS_OK; +} + nsresult nsImapMockChannel::Create(const nsIID &iid, void ** aInstancePtrResult) { /* note this new macro for assertions...they can take a string describing the assertion */ diff --git a/mailnews/imap/src/nsImapProtocol.h b/mailnews/imap/src/nsImapProtocol.h index baef51922c77..41df4f107044 100644 --- a/mailnews/imap/src/nsImapProtocol.h +++ b/mailnews/imap/src/nsImapProtocol.h @@ -554,7 +554,9 @@ protected: nsIURI * m_url; nsCOMPtr m_loadGroup; nsCOMPtr m_channelListener; - nsCOMPtr m_channelContext; + // non owning ref of the context in order to fix a circular ref count + // because the context is already the uri... + nsISupports * m_channelContext; }; #endif // nsImapProtocol_h___ diff --git a/mailnews/imap/src/nsImapUtils.cpp b/mailnews/imap/src/nsImapUtils.cpp index b74c22ad552b..c4cdcb61a0dd 100644 --- a/mailnews/imap/src/nsImapUtils.cpp +++ b/mailnews/imap/src/nsImapUtils.cpp @@ -152,7 +152,8 @@ nsImapURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult) NS_MsgHashIfNecessary(parentName); parentName += sbdSep; pathResult += (const char *) parentName; - parentName = leafName; + // this fixes a strange purify warning. + parentName = (const char *) leafName; dirEnd = parentName.FindChar('/'); } if (!leafName.IsEmpty()) {