Bug 1337865 - fix some leaking objects in mailnews/news. r=aceman
authorJorg K <jorgk@jorgk.com>
Sun, 26 Feb 2017 16:05:38 +0100
changeset 21219 ef7420896e68b4a9ffd30c7ad50ac0cb9c25b990
parent 21218 5f72602f1ff089df3a141c104facc656efdc6cd8
child 21220 39ee657ffbfd508614ff577604ab750b18cf5061
push id12890
push usermozilla@jorgk.com
push dateSun, 26 Feb 2017 15:12:02 +0000
treeherdercomm-central@63e348c30e23 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1337865
Bug 1337865 - fix some leaking objects in mailnews/news. r=aceman
mailnews/news/src/nsNNTPProtocol.cpp
mailnews/news/src/nsNewsFolder.cpp
mailnews/news/src/nsNntpService.cpp
--- a/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mailnews/news/src/nsNNTPProtocol.cpp
@@ -670,32 +670,28 @@ nsresult nsNNTPProtocol::ReadFromMemCach
     nsCOMPtr<nsIInputStreamPump> pump;
     rv = NS_NewInputStreamPump(getter_AddRefs(pump), cacheStream);
     if (NS_FAILED(rv)) return rv;
 
     nsCString group;
     // do this to get m_key set, so that marking the message read will work.
     rv = ParseURL(m_url, group, m_messageID);
 
-    nsNntpCacheStreamListener * cacheListener = new nsNntpCacheStreamListener();
-    if (!cacheListener)
-       return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ADDREF(cacheListener);
+    RefPtr<nsNntpCacheStreamListener> cacheListener =
+      new nsNntpCacheStreamListener();
 
     SetLoadGroup(m_loadGroup);
     m_typeWanted = ARTICLE_WANTED;
 
     nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningURL);
     cacheListener->Init(m_channelListener, static_cast<nsIChannel *>(this), mailnewsUrl);
 
     mContentType = ""; // reset the content type for the upcoming read....
 
     rv = pump->AsyncRead(cacheListener, m_channelContext);
-    NS_RELEASE(cacheListener);
 
     if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
     {
       // we're not calling nsMsgProtocol::AsyncRead(), which calls nsNNTPProtocol::LoadUrl, so we need to take care of some stuff it does.
       m_channelListener = nullptr;
       return rv;
     }
   }
@@ -741,33 +737,29 @@ bool nsNNTPProtocol::ReadFromLocalCache(
       // folder sink?) We also need to set the transfer offset to the message offset
       if (fileStream && NS_SUCCEEDED(rv))
       {
         // dougt - This may break the ablity to "cancel" a read from offline mail reading.
         // fileChannel->SetLoadGroup(m_loadGroup);
 
         m_typeWanted = ARTICLE_WANTED;
 
-        nsNntpCacheStreamListener * cacheListener = new nsNntpCacheStreamListener();
-        if (!cacheListener)
-          return false;
-
-        NS_ADDREF(cacheListener);
+        RefPtr<nsNntpCacheStreamListener> cacheListener =
+          new nsNntpCacheStreamListener();
+
         cacheListener->Init(m_channelListener, static_cast<nsIChannel *>(this), mailnewsUrl);
 
         // create a stream pump that will async read the specified amount of data.
         // XXX make size 64-bit int
         nsCOMPtr<nsIInputStreamPump> pump;
         rv = NS_NewInputStreamPump(getter_AddRefs(pump),
                                    fileStream, offset, (int64_t) size);
         if (NS_SUCCEEDED(rv))
           rv = pump->AsyncRead(cacheListener, m_channelContext);
 
-        NS_RELEASE(cacheListener);
-
         if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
         {
           mContentType.Truncate();
           m_channelListener = nullptr;
           NNTP_LOG_NOTE("Loading message from offline storage");
           return true;
         }
       }
--- a/mailnews/news/src/nsNewsFolder.cpp
+++ b/mailnews/news/src/nsNewsFolder.cpp
@@ -1622,16 +1622,17 @@ NS_IMETHODIMP nsMsgNewsFolder::DownloadA
     }
   }
   DownloadNewsArticlesToOfflineStore *downloadState = new DownloadNewsArticlesToOfflineStore(msgWindow, mDatabase, this);
   if (!downloadState)
     return NS_ERROR_OUT_OF_MEMORY;
   m_downloadingMultipleMessages = true;
   rv = downloadState->DownloadArticles(msgWindow, this, &srcKeyArray);
   (void) RefreshSizeOnDisk();
+  delete downloadState;
   return rv;
 }
 
 NS_IMETHODIMP nsMsgNewsFolder::DownloadMessagesForOffline(nsIArray *messages, nsIMsgWindow *window)
 {
   nsTArray<nsMsgKey> srcKeyArray;
   SetSaveArticleOffline(true); // ### TODO need to clear this when we've finished
   uint32_t count = 0;
@@ -1651,16 +1652,17 @@ NS_IMETHODIMP nsMsgNewsFolder::DownloadM
   }
   DownloadNewsArticlesToOfflineStore *downloadState = new DownloadNewsArticlesToOfflineStore(window, mDatabase, this);
   if (!downloadState)
     return NS_ERROR_OUT_OF_MEMORY;
   m_downloadingMultipleMessages = true;
 
   rv = downloadState->DownloadArticles(window, this, &srcKeyArray);
   (void) RefreshSizeOnDisk();
+  delete downloadState;
   return rv;
 }
 
 // line does not have a line terminator (e.g., CR or CRLF)
 NS_IMETHODIMP nsMsgNewsFolder::NotifyDownloadedLine(const char *line, nsMsgKey keyOfArticle)
 {
   nsresult rv = NS_OK;
   if (m_downloadMessageForOfflineUse)
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -1720,23 +1720,19 @@ nsNntpService::MessageURIToMsgHdr(const 
   rv = folder->GetMessageHeader(msgKey, _retval);
   NS_ENSURE_SUCCESS(rv,rv);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNntpService::DownloadNewsgroupsForOffline(nsIMsgWindow *aMsgWindow, nsIUrlListener *aListener)
 {
-  nsresult rv = NS_OK;
-  nsMsgDownloadAllNewsgroups *newsgroupDownloader = new nsMsgDownloadAllNewsgroups(aMsgWindow, aListener);
-  if (newsgroupDownloader)
-    rv = newsgroupDownloader->ProcessNextGroup();
-  else
-    rv = NS_ERROR_OUT_OF_MEMORY;
-  return rv;
+  RefPtr<nsMsgDownloadAllNewsgroups> newsgroupDownloader =
+    new nsMsgDownloadAllNewsgroups(aMsgWindow, aListener);
+  return newsgroupDownloader->ProcessNextGroup();
 }
 
 NS_IMETHODIMP nsNntpService::GetCacheStorage(nsICacheStorage **result)
 {
   nsresult rv = NS_OK;
   if (!mCacheStorage)
   {
     nsCOMPtr<nsICacheStorageService> cacheStorageService =