Bug 1340972 - Part 2: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/local. r=aceman
authorJorg K <jorgk@jorgk.com>
Tue, 12 Sep 2017 13:40:19 +0200
changeset 29689 7ea1a92f307016b99e0dd879745cf8b0e71c7159
parent 29688 c58474b55551716c4b8ad0ea7f39568268741922
child 29690 0eec5f47782d4b5a18c3172ce5a53baf4687419e
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersaceman
bugs1340972
Bug 1340972 - Part 2: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/local. r=aceman
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsLocalUtils.cpp
mailnews/local/src/nsMailboxService.cpp
mailnews/local/src/nsMailboxUrl.cpp
mailnews/local/src/nsMovemailService.cpp
mailnews/local/src/nsNoneService.cpp
mailnews/local/src/nsPop3Service.cpp
mailnews/local/src/nsRssIncomingServer.cpp
mailnews/local/src/nsRssService.cpp
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -3737,17 +3737,17 @@ nsMsgLocalMailFolder::AddMessageBatch(ui
 
       msgStore->FinishNewMessage(outFileStream, newHdr);
       outFileStream->Close();
       outFileStream = nullptr;
       newMailParser->OnStopRequest(nullptr, nullptr, NS_OK);
       newMailParser->EndMsgDownload();
       hdrArray->AppendElement(newHdr, false);
     }
-    NS_ADDREF(*aHdrArray = hdrArray);
+    hdrArray.forget(aHdrArray);
   }
   ReleaseSemaphore(static_cast<nsIMsgLocalMailFolder*>(this));
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgLocalMailFolder::WarnIfLocalFileTooBig(nsIMsgWindow *aWindow,
                                             int64_t aSpaceRequested,
--- a/mailnews/local/src/nsLocalUtils.cpp
+++ b/mailnews/local/src/nsLocalUtils.cpp
@@ -44,38 +44,38 @@ nsGetMailboxServer(const char *uriStr, n
   // find all local mail "no servers" matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> none_server;
   aUrl->SetScheme(NS_LITERAL_CSTRING("none"));
   // No unescaping of username or hostname done here.
   // The unescaping is done inside of FindServerByURI
   rv = accountManager->FindServerByURI(aUrl, false,
                                   getter_AddRefs(none_server));
   if (NS_SUCCEEDED(rv)) {
-    NS_ADDREF(*aResult = none_server);
+    none_server.forget(aResult);
     return rv;
   }
   
   // if that fails, look for the rss hosts matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> rss_server;
   aUrl->SetScheme(NS_LITERAL_CSTRING("rss"));
   rv = accountManager->FindServerByURI(aUrl, false,
                                   getter_AddRefs(rss_server));
   if (NS_SUCCEEDED(rv))
   {
-     NS_ADDREF(*aResult = rss_server);
+     rss_server.forget(aResult);
      return rv;
   }
 #ifdef HAVE_MOVEMAIL
   // find all movemail "servers" matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> movemail_server;
   aUrl->SetScheme(NS_LITERAL_CSTRING("movemail"));
   rv = accountManager->FindServerByURI(aUrl, false,
                                   getter_AddRefs(movemail_server));
   if (NS_SUCCEEDED(rv)) {
-    NS_ADDREF(*aResult = movemail_server);
+    movemail_server.forget(aResult);
     return rv;
   }
 #endif /* HAVE_MOVEMAIL */
 
   // if that fails, look for the pop hosts matching the given hostname
   nsCOMPtr<nsIMsgIncomingServer> server;
   if (NS_FAILED(rv)) 
   {
@@ -89,36 +89,32 @@ nsGetMailboxServer(const char *uriStr, n
     {
       aUrl->SetScheme(NS_LITERAL_CSTRING("imap"));
       rv = accountManager->FindServerByURI(aUrl, false,
                                     getter_AddRefs(server));
     }
   }
   if (NS_SUCCEEDED(rv)) 
   {
-    NS_ADDREF(*aResult = server);
+    server.forget(aResult);
     return rv;
   }
 
 // if you fail after looking at all "pop3", "movemail" and "none" servers, you fail.
 return rv;
 }
 
 static nsresult
 nsLocalURI2Server(const char* uriStr,
                   nsIMsgIncomingServer ** aResult)
 {
   nsresult rv;
-
-
   nsCOMPtr<nsIMsgIncomingServer> server;
   rv = nsGetMailboxServer(uriStr, getter_AddRefs(server));
-
-  NS_IF_ADDREF(*aResult = server);
-
+  server.forget(aResult);
   return rv;
 }
 
 // given rootURI and rootURI##folder, return on-disk path of folder
 nsresult
 nsLocalURI2Path(const char* rootURI, const char* uriStr,
                 nsCString& pathResult)
 {
--- a/mailnews/local/src/nsMailboxService.cpp
+++ b/mailnews/local/src/nsMailboxService.cpp
@@ -68,18 +68,17 @@ nsresult nsMailboxService::ParseMailbox(
     if (aUrlListener)
       url->RegisterListener(aUrlListener);
 
     rv = RunMailboxUrl(url, nullptr);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (aURL)
     {
-      *aURL = url;
-      NS_IF_ADDREF(*aURL);
+      url.forget(aURL);
     }
   }
 
   return rv;
 }
 
 nsresult nsMailboxService::CopyMessage(const char * aSrcMailboxURI,
                               nsIStreamListener * aMailboxCopyHandler,
--- a/mailnews/local/src/nsMailboxUrl.cpp
+++ b/mailnews/local/src/nsMailboxUrl.cpp
@@ -89,18 +89,17 @@ nsresult nsMailboxUrl::SetMailboxCopyHan
 }
 
 nsresult nsMailboxUrl::GetMailboxCopyHandler(nsIStreamListener ** aMailboxCopyHandler)
 {
   NS_ENSURE_ARG_POINTER(aMailboxCopyHandler);
 
   if (aMailboxCopyHandler)
   {
-    *aMailboxCopyHandler = m_mailboxCopyHandler;
-    NS_IF_ADDREF(*aMailboxCopyHandler);
+    NS_IF_ADDREF(*aMailboxCopyHandler = m_mailboxCopyHandler);
   }
 
   return  NS_OK;
 }
 
 nsresult nsMailboxUrl::GetMessageKey(nsMsgKey* aMessageKey)
 {
   *aMessageKey = m_messageKey;
--- a/mailnews/local/src/nsMovemailService.cpp
+++ b/mailnews/local/src/nsMovemailService.cpp
@@ -576,17 +576,17 @@ nsMovemailService::GetDefaultLocalPath(n
     rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
   if (NS_FAILED(rv)) return rv;
 
   if (!havePref || !exists) {
     rv = NS_SetPersistentFile(PREF_MAIL_ROOT_MOVEMAIL_REL, PREF_MAIL_ROOT_MOVEMAIL, localFile);
     NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set root dir pref.");
   }
 
-  NS_IF_ADDREF(*aResult = localFile);
+  localFile.forget(aResult);
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsMovemailService::GetServerIID(nsIID* *aServerIID)
 {
   *aServerIID = new nsIID(NS_GET_IID(nsIMovemailIncomingServer));
--- a/mailnews/local/src/nsNoneService.cpp
+++ b/mailnews/local/src/nsNoneService.cpp
@@ -59,22 +59,20 @@ nsNoneService::GetDefaultLocalPath(nsIFi
         rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
     if (NS_FAILED(rv)) return rv;
     
     if (!havePref || !exists) 
     {
         rv = NS_SetPersistentFile(PREF_MAIL_ROOT_NONE_REL, PREF_MAIL_ROOT_NONE, localFile);
         NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set root dir pref.");
     }
-        
-    NS_IF_ADDREF(*aResult = localFile);
+
+    localFile.forget(aResult);
     return NS_OK;
-
 }
-    
 
 NS_IMETHODIMP
 nsNoneService::GetServerIID(nsIID* *aServerIID)
 {
     *aServerIID = new nsIID(NS_GET_IID(nsINoIncomingServer));
     return NS_OK;
 }
 
--- a/mailnews/local/src/nsPop3Service.cpp
+++ b/mailnews/local/src/nsPop3Service.cpp
@@ -133,17 +133,17 @@ nsresult nsPop3Service::GetMail(bool dow
   }
 
   NS_ENSURE_TRUE(url, rv);
 
   if (NS_SUCCEEDED(rv))
     rv = RunPopUrl(server, url);
 
   if (aURL) // we already have a ref count on pop3url...
-    NS_IF_ADDREF(*aURL = url);
+    url.forget(aURL);
 
   return rv;
 }
 
 NS_IMETHODIMP nsPop3Service::VerifyLogon(nsIMsgIncomingServer *aServer,
                                          nsIUrlListener *aUrlListener,
                                          nsIMsgWindow *aMsgWindow,
                                          nsIURI **aURL)
@@ -552,17 +552,17 @@ nsPop3Service::GetDefaultLocalPath(nsIFi
         rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!havePref || !exists) {
         rv = NS_SetPersistentFile(PREF_MAIL_ROOT_POP3_REL, PREF_MAIL_ROOT_POP3, localFile);
         NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set root dir pref.");
     }
 
-    NS_IF_ADDREF(*aResult = localFile);
+    localFile.forget(aResult);
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsPop3Service::GetServerIID(nsIID **aServerIID)
 {
     *aServerIID = new nsIID(NS_GET_IID(nsIPop3IncomingServer));
--- a/mailnews/local/src/nsRssIncomingServer.cpp
+++ b/mailnews/local/src/nsRssIncomingServer.cpp
@@ -65,17 +65,17 @@ nsresult nsRssIncomingServer::FillInData
   nsresult rv;
   // Get the local path for this server.
   nsCOMPtr<nsIFile> localFile;
   rv = GetLocalPath(getter_AddRefs(localFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Append the name of the subscriptions data source.
   rv = localFile->Append(aDataSourceName);
-  NS_IF_ADDREF(*aLocation = localFile);
+  localFile.forget(aLocation);
   return rv;
 }
 
 // nsIRSSIncomingServer methods
 NS_IMETHODIMP nsRssIncomingServer::GetSubscriptionsDataSourcePath(nsIFile ** aLocation)
 {
   return FillInDataSourcePath(NS_LITERAL_STRING("feeds.rdf"), aLocation);
 }
--- a/mailnews/local/src/nsRssService.cpp
+++ b/mailnews/local/src/nsRssService.cpp
@@ -33,20 +33,19 @@ NS_IMETHODIMP nsRssService::GetDefaultLo
     dirService->Get(NS_APP_MAIL_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(localFile));
     if (!localFile) return NS_ERROR_FAILURE;
 
     bool exists;
     nsresult rv = localFile->Exists(&exists);
     if (NS_SUCCEEDED(rv) && !exists)
         rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
     if (NS_FAILED(rv)) return rv;
-   
-    NS_IF_ADDREF(*aDefaultLocalPath = localFile);
+
+    localFile.forget(aDefaultLocalPath);
     return NS_OK;
-
 }
 
 NS_IMETHODIMP nsRssService::SetDefaultLocalPath(nsIFile * aDefaultLocalPath)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP nsRssService::GetServerIID(nsIID * *aServerIID)