Bug 1340972 - Part 4: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/db. r=aceman
authorJorg K <jorgk@jorgk.com>
Tue, 12 Sep 2017 22:48:35 +0200
changeset 29694 91ed5528ef118d3f75f0504e4e3a667eb8cf7688
parent 29693 040f15fdc501a091a5a39b0a3017b0f6d971adc4
child 29695 3365d035c78dafad410c222e25a511e35409f2a5
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersaceman
bugs1340972
Bug 1340972 - Part 4: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/db. r=aceman
mailnews/db/msgdb/src/nsDBFolderInfo.cpp
mailnews/db/msgdb/src/nsMailDatabase.cpp
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/db/msgdb/src/nsMsgHdr.cpp
mailnews/db/msgdb/src/nsMsgThread.cpp
--- a/mailnews/db/msgdb/src/nsDBFolderInfo.cpp
+++ b/mailnews/db/msgdb/src/nsDBFolderInfo.cpp
@@ -923,18 +923,17 @@ nsTransferDBFolderInfo::~nsTransferDBFol
 }
 
 /* void GetTransferInfo (out nsIDBFolderInfo transferInfo); */
 NS_IMETHODIMP nsDBFolderInfo::GetTransferInfo(nsIDBFolderInfo **transferInfo)
 {
   NS_ENSURE_ARG_POINTER(transferInfo);
 
   nsTransferDBFolderInfo *newInfo = new nsTransferDBFolderInfo;
-  *transferInfo = newInfo;
-  NS_ADDREF(newInfo);
+  NS_ADDREF(*transferInfo = newInfo);
 
   mdb_count numCells;
   mdbYarn cellYarn;
   mdb_column cellColumn;
   char columnName[100];
   mdbYarn cellName = { columnName, 0, sizeof(columnName), 0, 0, nullptr };
 
   NS_ASSERTION(m_mdbRow, "null row in getTransferInfo");
--- a/mailnews/db/msgdb/src/nsMailDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp
@@ -179,20 +179,18 @@ NS_IMETHODIMP nsMailDatabase::GetOffline
         NS_ENSURE_SUCCESS(err, err);
       }
       if (offlineOpRow && !hasOid)
         m_mdbAllOfflineOpsTable->AddRow(GetEnv(), offlineOpRow);
     }
     
     if (NS_SUCCEEDED(err) && offlineOpRow)
     {
-      *offlineOp = new nsMsgOfflineImapOperation(this, offlineOpRow);
-      if (*offlineOp)
-        (*offlineOp)->SetMessageKey(msgKey);
-      NS_IF_ADDREF(*offlineOp);
+      NS_IF_ADDREF(*offlineOp = new nsMsgOfflineImapOperation(this, offlineOpRow));
+      (*offlineOp)->SetMessageKey(msgKey);
     }
     if (!hasOid && m_dbFolderInfo)
     {
       // set initial value for flags so we don't lose them.
       nsCOMPtr <nsIMsgDBHdr> msgHdr;
       GetMsgHdrForKey(msgKey, getter_AddRefs(msgHdr));
       if (msgHdr)
       {
@@ -368,18 +366,17 @@ NS_IMETHODIMP nsMsgOfflineOpEnumerator::
 
   nsresult rv = NS_OK;
   if (!mNextPrefetched)
     rv = PrefetchNext();
   if (NS_SUCCEEDED(rv))
   {
     if (mResultOp) 
     {
-      *aItem = mResultOp;
-      NS_ADDREF(*aItem);
+      NS_ADDREF(*aItem = mResultOp);
       mNextPrefetched = false;
     }
   }
   return rv;
 }
 
 nsresult nsMsgOfflineOpEnumerator::PrefetchNext()
 {
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -2686,18 +2686,17 @@ NS_IMETHODIMP nsMsgDBEnumerator::GetNext
     return NS_ERROR_NULL_POINTER;
   nsresult rv = NS_OK;
   if (!mNextPrefetched)
     rv = PrefetchNext();
   if (NS_SUCCEEDED(rv))
   {
     if (mResultHdr)
     {
-      *aItem = mResultHdr;
-      NS_ADDREF(*aItem);
+      NS_ADDREF(*aItem = mResultHdr);
       mNextPrefetched = false;
     }
   }
   return rv;
 }
 
 nsresult nsMsgDBEnumerator::PrefetchNext()
 {
@@ -2832,33 +2831,27 @@ nsresult nsMsgFilteredDBEnumerator::Pref
 
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMETHODIMP
 nsMsgDatabase::EnumerateMessages(nsISimpleEnumerator* *result)
 {
   RememberLastUseTime();
   NS_ENSURE_ARG_POINTER(result);
-  nsMsgDBEnumerator* e = new nsMsgDBEnumerator(this, m_mdbAllMsgHeadersTable,
-                                               nullptr, nullptr);
-  if (!e)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(*result = e);
+  NS_ADDREF(*result = new nsMsgDBEnumerator(this, m_mdbAllMsgHeadersTable,
+                                            nullptr, nullptr));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgDatabase::ReverseEnumerateMessages(nsISimpleEnumerator* *result)
 {
   NS_ENSURE_ARG_POINTER(result);
-  nsMsgDBEnumerator* e = new nsMsgDBEnumerator(this, m_mdbAllMsgHeadersTable,
-                                               nullptr, nullptr, false);
-  if (!e)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(*result = e);
+  NS_ADDREF(*result = new nsMsgDBEnumerator(this, m_mdbAllMsgHeadersTable,
+                                            nullptr, nullptr, false));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgDatabase::GetFilterEnumerator(nsIArray *searchTerms, bool aReverse,
                                    nsISimpleEnumerator **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
@@ -3127,18 +3120,17 @@ NS_IMETHODIMP nsMsgDBThreadEnumerator::G
   *aItem = nullptr;
   nsresult rv = NS_OK;
   if (!mNextPrefetched)
     rv = PrefetchNext();
   if (NS_SUCCEEDED(rv))
   {
     if (mResultThread)
     {
-      *aItem = mResultThread;
-      NS_ADDREF(mResultThread);
+      NS_ADDREF(*aItem = mResultThread);
       mNextPrefetched = false;
     }
   }
   return rv;
 }
 
 
 nsresult nsMsgDBThreadEnumerator::PrefetchNext()
@@ -3209,20 +3201,17 @@ NS_IMETHODIMP nsMsgDBThreadEnumerator::H
   *aResult = !mDone;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgDatabase::EnumerateThreads(nsISimpleEnumerator* *result)
 {
   RememberLastUseTime();
-  nsMsgDBThreadEnumerator* e = new nsMsgDBThreadEnumerator(this, nullptr);
-  if (e == nullptr)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(*result = e);
+  NS_ADDREF(*result = new nsMsgDBThreadEnumerator(this, nullptr));
   return NS_OK;
 }
 
 // only return headers with a particular flag set
 static nsresult
 nsMsgFlagSetFilter(nsIMsgDBHdr *msg, void *closure)
 {
   uint32_t msgFlags, desiredFlags;
@@ -3230,21 +3219,17 @@ nsMsgFlagSetFilter(nsIMsgDBHdr *msg, voi
   msg->GetFlags(&msgFlags);
   return (msgFlags & desiredFlags) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult
 nsMsgDatabase::EnumerateMessagesWithFlag(nsISimpleEnumerator* *result, uint32_t *pFlag)
 {
   RememberLastUseTime();
-
-  nsMsgDBEnumerator* e = new nsMsgDBEnumerator(this, m_mdbAllMsgHeadersTable, nsMsgFlagSetFilter, pFlag);
-  if (!e)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(*result = e);
+  NS_ADDREF(*result = new nsMsgDBEnumerator(this, m_mdbAllMsgHeadersTable, nsMsgFlagSetFilter, pFlag));
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDatabase::CreateNewHdr(nsMsgKey key, nsIMsgDBHdr **pnewHdr)
 {
   nsresult  err = NS_OK;
   nsIMdbRow    *hdrRow = nullptr;
   struct mdbOid allMsgHdrsTableOID;
@@ -4855,18 +4840,17 @@ NS_IMETHODIMP nsMsgDatabase::GetMsgReten
       m_retentionSettings->SetDaysToKeepHdrs(daysToKeepHdrs);
       m_retentionSettings->SetNumHeadersToKeep(numHeadersToKeep);
       m_retentionSettings->SetDaysToKeepBodies(daysToKeepBodies);
       m_retentionSettings->SetUseServerDefaults(useServerDefaults);
       m_retentionSettings->SetCleanupBodiesByDays(cleanupBodiesByDays);
       m_retentionSettings->SetApplyToFlaggedMessages(applyToFlaggedMessages);
     }
   }
-  *retentionSettings = m_retentionSettings;
-  NS_IF_ADDREF(*retentionSettings);
+  NS_IF_ADDREF(*retentionSettings = m_retentionSettings);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDatabase::SetMsgDownloadSettings(nsIMsgDownloadSettings *downloadSettings)
 {
   m_downloadSettings = downloadSettings;
   if (downloadSettings && m_dbFolderInfo)
   {
@@ -4914,18 +4898,17 @@ NS_IMETHODIMP nsMsgDatabase::GetMsgDownl
       m_dbFolderInfo->GetUint32Property("ageLimit", 0, &ageLimitOfMsgsToDownload);
 
       m_downloadSettings->SetUseServerDefaults(useServerDefaults);
       m_downloadSettings->SetDownloadByDate(downloadByDate);
       m_downloadSettings->SetDownloadUnreadOnly(downloadUnreadOnly);
       m_downloadSettings->SetAgeLimitOfMsgsToDownload(ageLimitOfMsgsToDownload);
     }
   }
-  *downloadSettings = m_downloadSettings;
-  NS_IF_ADDREF(*downloadSettings);
+  NS_IF_ADDREF(*downloadSettings = m_downloadSettings);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDatabase::ApplyRetentionSettings(nsIMsgRetentionSettings *aMsgRetentionSettings,
                                                     bool aDeleteViaFolder)
 {
   NS_ENSURE_ARG_POINTER(aMsgRetentionSettings);
   nsresult rv = NS_OK;
@@ -5385,20 +5368,17 @@ nsresult nsMsgDatabase::GetSearchResults
 
 NS_IMETHODIMP
 nsMsgDatabase::GetCachedHits(const char *aSearchFolderUri, nsISimpleEnumerator **aEnumerator)
 {
   nsCOMPtr <nsIMdbTable> table;
   (void) GetSearchResultsTable(aSearchFolderUri, false, getter_AddRefs(table));
   if (!table)
     return NS_ERROR_FAILURE; // expected result for no cached hits
-  nsMsgDBEnumerator* e = new nsMsgDBEnumerator(this, table, nullptr, nullptr);
-  if (e == nullptr)
-      return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(*aEnumerator = e);
+  NS_ADDREF(*aEnumerator = new nsMsgDBEnumerator(this, table, nullptr, nullptr));
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDatabase::RefreshCache(const char *aSearchFolderUri, uint32_t aNumKeys, nsMsgKey *aNewHits, uint32_t *aNumBadHits, nsMsgKey **aStaleHits)
 {
   nsCOMPtr <nsIMdbTable> table;
   nsresult err = GetSearchResultsTable(aSearchFolderUri, true, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(err, err);
--- a/mailnews/db/msgdb/src/nsMsgHdr.cpp
+++ b/mailnews/db/msgdb/src/nsMsgHdr.cpp
@@ -650,18 +650,17 @@ NS_IMETHODIMP nsMsgHdr::GetThreadParent(
 }
 
 NS_IMETHODIMP nsMsgHdr::GetFolder(nsIMsgFolder **result)
 {
   NS_ENSURE_ARG(result);
 
   if (m_mdb && m_mdb->m_folder)
   {
-    *result = m_mdb->m_folder;
-    NS_ADDREF(*result);
+    NS_ADDREF(*result = m_mdb->m_folder);
   }
   else
     *result = nullptr;
   return NS_OK;
 }
 
 nsresult nsMsgHdr::SetStringColumn(const char *str, mdb_token token)
 {
@@ -1078,15 +1077,11 @@ void nsMsgPropertyEnumerator::PrefetchNe
     }
   }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMETHODIMP nsMsgHdr::GetPropertyEnumerator(nsIUTF8StringEnumerator** _result)
 {
-  nsMsgPropertyEnumerator* enumerator = new nsMsgPropertyEnumerator(this);
-  if (!enumerator)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  NS_ADDREF(*_result = enumerator);
+  NS_ADDREF(*_result = new nsMsgPropertyEnumerator(this));
   return NS_OK;
 }
--- a/mailnews/db/msgdb/src/nsMsgThread.cpp
+++ b/mailnews/db/msgdb/src/nsMsgThread.cpp
@@ -828,18 +828,17 @@ NS_IMETHODIMP nsMsgThreadEnumerator::Has
   if (mNeedToPrefetch)
     Prefetch();
   *aResult = !mDone;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgThread::EnumerateMessages(nsMsgKey parentKey, nsISimpleEnumerator* *result)
 {
-  nsMsgThreadEnumerator* e = new nsMsgThreadEnumerator(this, parentKey, nullptr, nullptr);
-  NS_ADDREF(*result = e);
+  NS_ADDREF(*result = new nsMsgThreadEnumerator(this, parentKey, nullptr, nullptr));
   return NS_OK;
 }
 
 nsresult nsMsgThread::ReparentMsgsWithInvalidParent(uint32_t numChildren, nsMsgKey threadParentKey)
 {
   nsresult rv = NS_OK;
   // run through looking for messages that don't have a correct parent,
   // i.e., a parent that's in the thread!