From f0370e6b8533b4107f996d52fecc0759682f5514 Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Thu, 7 Sep 2000 14:13:23 +0000 Subject: [PATCH] some fixes for news memory leaks r=mscott 51359 --- mailnews/base/util/nsMsgMailNewsUrl.cpp | 1 + mailnews/news/src/nsNNTPProtocol.cpp | 17 ++++++++++++++++- mailnews/news/src/nsNntpIncomingServer.cpp | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mailnews/base/util/nsMsgMailNewsUrl.cpp b/mailnews/base/util/nsMsgMailNewsUrl.cpp index 1fa7f4ed5890..670bbd7270a2 100644 --- a/mailnews/base/util/nsMsgMailNewsUrl.cpp +++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp @@ -104,6 +104,7 @@ nsresult nsMsgMailNewsUrl::SetUrlState(PRBool aRunningUrl, nsresult aExitCode) else { m_urlListeners->OnStopRunningUrl(this, aExitCode); + m_loadGroup = nsnull; // try to break circular refs. } } else diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 7338a15cb41b..20119f02a5b1 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -584,7 +584,8 @@ NS_IMETHODIMP nsNNTPProtocol::Initialize(nsIURI * aURL, nsIMsgWindow *aMsgWindow m_dataBuf = (char *) PR_Malloc(sizeof(char) * OUTPUT_BUFFER_SIZE); m_dataBufSize = OUTPUT_BUFFER_SIZE; - m_lineStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, CRLF, PR_TRUE /* create new lines */); + if (!m_lineStreamBuffer) + m_lineStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, CRLF, PR_TRUE /* create new lines */); m_nextState = SEND_FIRST_NNTP_COMMAND; m_nextStateAfterResponse = NNTP_CONNECT; @@ -5034,6 +5035,9 @@ nsresult nsNNTPProtocol::ProcessProtocolState(nsIURI * url, nsIInputStream * inp NS_IMETHODIMP nsNNTPProtocol::CloseConnection() { SendData(nsnull, NNTP_CMD_QUIT); // this will cause OnStopRequest get called, which will call CloseSocket() + // break some cycles + m_newsHost = nsnull; + m_nntpServer = nsnull; return NS_OK; } @@ -5081,7 +5085,18 @@ nsresult nsNNTPProtocol::CleanupAfterRunningUrl() PR_FREEIF(m_cancelID); m_cancelID = nsnull; + mDisplayInputStream = nsnull; + mDisplayOutputStream = nsnull; + m_channelListener = nsnull; + m_channelContext = nsnull; + m_loadGroup = nsnull; + mProgressEventSink = nsnull; + SetOwner(nsnull); + m_runningURL = null_nsCOMPtr(); + m_url = null_nsCOMPtr(); + m_originalUrl = null_nsCOMPtr(); + m_connectionBusy = PR_FALSE; return NS_OK; } diff --git a/mailnews/news/src/nsNntpIncomingServer.cpp b/mailnews/news/src/nsNntpIncomingServer.cpp index 2c7061d5814a..23cbee5f05d5 100644 --- a/mailnews/news/src/nsNntpIncomingServer.cpp +++ b/mailnews/news/src/nsNntpIncomingServer.cpp @@ -409,10 +409,13 @@ nsNntpIncomingServer::CloseCachedConnections() if (NS_FAILED(rv)) return rv; for (PRUint32 i = 0; i < cnt; i++) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); + aSupport = getter_AddRefs(m_connectionCache->ElementAt(0)); connection = do_QueryInterface(aSupport); if (connection) + { rv = connection->CloseConnection(); + RemoveConnection(connection); + } } } rv = WriteNewsrcFile();