Bug 1340972 - Part 14: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/base/src. r=aceman
authorJorg K <jorgk@jorgk.com>
Fri, 15 Sep 2017 00:32:14 +0200
changeset 28889 254747a8daa5e96faeb4f3c389841e61365cb82b
parent 28888 a0bd8f2b70bef081d138819a6363a1917da55cbe
child 28890 ebe355c1d925132c3dd4ce6acca6506079518d89
push id2027
push userclokep@gmail.com
push dateFri, 22 Sep 2017 15:34:57 +0000
treeherdercomm-beta@cffa2d0e5946 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1340972
Bug 1340972 - Part 14: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/base/src. r=aceman
mailnews/base/src/nsMailDirProvider.cpp
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMessengerWinIntegration.cpp
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/src/nsMsgAccountManagerDS.cpp
mailnews/base/src/nsMsgDBView.cpp
mailnews/base/src/nsMsgFolderCacheElement.cpp
mailnews/base/src/nsMsgFolderDataSource.cpp
mailnews/base/src/nsMsgGroupThread.cpp
mailnews/base/src/nsMsgMailSession.cpp
mailnews/base/src/nsMsgOfflineManager.cpp
mailnews/base/src/nsMsgQuickSearchDBView.cpp
mailnews/base/src/nsMsgRDFDataSource.cpp
mailnews/base/src/nsMsgRDFUtils.cpp
mailnews/base/src/nsMsgSearchDBView.cpp
mailnews/base/src/nsMsgSpecialViews.cpp
mailnews/base/src/nsMsgXFViewThread.cpp
mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
mailnews/base/src/nsSubscribableServer.cpp
mailnews/base/src/nsSubscribeDataSource.cpp
--- a/mailnews/base/src/nsMailDirProvider.cpp
+++ b/mailnews/base/src/nsMailDirProvider.cpp
@@ -121,17 +121,17 @@ nsMailDirProvider::GetFiles(const char *
   // xpcshell-tests don't have XRE_EXTENSIONS_DIR_LIST, so accept a null return here.
   dirSvc->Get(XRE_EXTENSIONS_DIR_LIST,
               NS_GET_IID(nsISimpleEnumerator),
               getter_AddRefs(extensionsEnum));
 
   rv = NS_NewUnionEnumerator(getter_AddRefs(combinedEnumerator), directoryEnumerator, extensionsEnum);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  NS_IF_ADDREF(*aResult = new AppendingEnumerator(combinedEnumerator));
+  NS_ADDREF(*aResult = new AppendingEnumerator(combinedEnumerator));
   return NS_SUCCESS_AGGREGATE_RESULT;
 }
 
 NS_IMPL_ISUPPORTS(nsMailDirProvider::AppendingEnumerator,
                    nsISimpleEnumerator)
 
 NS_IMETHODIMP
 nsMailDirProvider::AppendingEnumerator::HasMoreElements(bool *aResult)
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -1619,20 +1619,17 @@ nsMessenger::Redo(nsIMsgWindow *msgWindo
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsMessenger::GetTransactionManager(nsITransactionManager* *aTxnMgr)
 {
   NS_ENSURE_TRUE(mTxnMgr && aTxnMgr, NS_ERROR_NULL_POINTER);
-
-  *aTxnMgr = mTxnMgr;
-  NS_ADDREF(*aTxnMgr);
-
+  NS_ADDREF(*aTxnMgr = mTxnMgr);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMessenger::SetDocumentCharset(const nsACString& aCharacterSet)
 {
   // We want to redisplay the currently selected message (if any) but forcing the
   // redisplay to use characterSet
   if (!mLastDisplayURI.IsEmpty())
@@ -2132,19 +2129,18 @@ nsMessenger::GetLastSaveDirectory(nsIFil
 {
   nsresult rv;
   nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
   // this can fail, and it will, on the first time we call it, as there is no default for this pref.
   nsCOMPtr <nsIFile> localFile;
   rv = prefBranch->GetComplexValue(MESSENGER_SAVE_DIR_PREF_NAME, NS_GET_IID(nsIFile), getter_AddRefs(localFile));
-  if (NS_SUCCEEDED(rv)) {
-    NS_IF_ADDREF(*aLastSaveDir = localFile);
-  }
+  if (NS_SUCCEEDED(rv))
+    localFile.forget(aLastSaveDir);
   return rv;
 }
 
 nsresult
 nsMessenger::SetLastSaveDirectory(nsIFile *aLocalFile)
 {
   nsresult rv;
   nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
--- a/mailnews/base/src/nsMessengerWinIntegration.cpp
+++ b/mailnews/base/src/nsMessengerWinIntegration.cpp
@@ -385,17 +385,17 @@ nsresult nsMessengerWinIntegration::GetS
 {
   NS_ENSURE_ARG_POINTER(aBundle);
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
   NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
   nsCOMPtr<nsIStringBundle> bundle;
   bundleService->CreateBundle("chrome://messenger/locale/messenger.properties",
                               getter_AddRefs(bundle));
-  NS_IF_ADDREF(*aBundle = bundle);
+  bundle.forget(aBundle);
   return NS_OK;
 }
 
 #ifndef MOZ_THUNDERBIRD
 nsresult nsMessengerWinIntegration::ShowAlertMessage(const nsString& aAlertTitle,
                                                      const nsString& aAlertText,
                                                      const nsACString& aFolderURI)
 {
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -922,17 +922,17 @@ nsMsgAccountManager::GetAccounts(nsIArra
     {
       bool hidden = false;
       server->GetHidden(&hidden);
       if (hidden)
         continue;
     }
     accounts->AppendElement(existingAccount, false);
   }
-  NS_IF_ADDREF(*_retval = accounts);
+  accounts.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgAccountManager::GetAllIdentities(nsIArray **_retval)
 {
   nsresult rv = LoadAccounts();
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1978,17 +1978,17 @@ nsMsgAccountManager::findServerInternal(
         (hostname.IsEmpty() || thisHostname.Equals(hostname, nsCaseInsensitiveCStringComparator())) &&
         (!(port != 0) || (port == thisPort)) &&
         (username.IsEmpty() || thisUsername.Equals(username)))
     {
       // stop on first find; cache for next time
       if (!aRealFlag)
         SetLastServerFound(server, hostname, username, port, type);
 
-      NS_ADDREF(*aResult = server);
+      NS_ADDREF(*aResult = server);  // Was populated from member variable.
       return NS_OK;
     }
   }
 
   return NS_ERROR_UNEXPECTED;
 }
 
 NS_IMETHODIMP
--- a/mailnews/base/src/nsMsgAccountManagerDS.cpp
+++ b/mailnews/base/src/nsMsgAccountManagerDS.cpp
@@ -761,18 +761,17 @@ nsMsgAccountManagerDataSource::getAccoun
     mAccountArcsOut->AppendElement(kNC_Name, false);
     mAccountArcsOut->AppendElement(kNC_FolderTreeName, false);
     mAccountArcsOut->AppendElement(kNC_FolderTreeSimpleName, false);
     mAccountArcsOut->AppendElement(kNC_NameSort, false);
     mAccountArcsOut->AppendElement(kNC_FolderTreeNameSort, false);
     mAccountArcsOut->AppendElement(kNC_PageTag, false);
   }
 
-  *aResult = mAccountArcsOut;
-  NS_IF_ADDREF(*aResult);
+  NS_IF_ADDREF(*aResult = mAccountArcsOut);
   return NS_OK;
 }
 
 nsresult
 nsMsgAccountManagerDataSource::getAccountRootArcs(nsIMutableArray **aResult)
 {
   nsresult rv;
   if (!mAccountRootArcsOut) {
@@ -786,18 +785,17 @@ nsMsgAccountManagerDataSource::getAccoun
     mAccountRootArcsOut->AppendElement(kNC_Name, false);
     mAccountRootArcsOut->AppendElement(kNC_FolderTreeName, false);
     mAccountRootArcsOut->AppendElement(kNC_FolderTreeSimpleName, false);
     mAccountRootArcsOut->AppendElement(kNC_NameSort, false);
     mAccountRootArcsOut->AppendElement(kNC_FolderTreeNameSort, false);
     mAccountRootArcsOut->AppendElement(kNC_PageTag, false);
   }
 
-  *aResult = mAccountRootArcsOut;
-  NS_IF_ADDREF(*aResult);
+  NS_IF_ADDREF(*aResult = mAccountRootArcsOut);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgAccountManagerDataSource::HasArcOut(nsIRDFResource *source, nsIRDFResource *aArc, bool *result)
 {
   if (aArc == kNC_Settings) {
     // based on createSettingsResources()
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -1013,18 +1013,17 @@ NS_IMETHODIMP nsMsgDBView::SetCellText(i
 NS_IMETHODIMP nsMsgDBView::GetRowCount(int32_t *aRowCount)
 {
   *aRowCount = GetSize();
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDBView::GetSelection(nsITreeSelection * *aSelection)
 {
-  *aSelection = mTreeSelection;
-  NS_IF_ADDREF(*aSelection);
+  NS_IF_ADDREF(*aSelection = mTreeSelection);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDBView::SetSelection(nsITreeSelection * aSelection)
 {
   mTreeSelection = aSelection;
   return NS_OK;
 }
@@ -1619,18 +1618,17 @@ nsresult nsMsgDBView::GetMsgHdrForViewIn
     return NS_MSG_INVALID_DBVIEW_INDEX;
 
   nsMsgKey key = m_keys[index];
   if (key == nsMsgKey_None || !m_db)
     return NS_MSG_INVALID_DBVIEW_INDEX;
 
   if (key == m_cachedMsgKey)
   {
-    *msgHdr = m_cachedHdr;
-    NS_IF_ADDREF(*msgHdr);
+    NS_IF_ADDREF(*msgHdr = m_cachedHdr);
   }
   else
   {
     rv = m_db->GetMsgHdrForKey(key, msgHdr);
     if (NS_SUCCEEDED(rv))
     {
       m_cachedHdr = *msgHdr;
       m_cachedMsgKey = key;
@@ -7775,19 +7773,16 @@ NS_IMETHODIMP nsMsgDBView::SelectMsgByKe
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
 {
   nsMsgDBView* newMsgDBView = new nsMsgDBView();
 
-  if (!newMsgDBView)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv,rv);
 
   NS_IF_ADDREF(*_retval = newMsgDBView);
   return NS_OK;
 }
 
 nsresult nsMsgDBView::CopyDBView(nsMsgDBView *aNewMsgDBView, nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater)
@@ -7958,17 +7953,17 @@ NS_IMETHODIMP nsMsgDBView::nsMsgViewHdrE
   // Ignore dummy header. We won't have empty groups, so
   // we know the view index is good.
   if (m_view->m_flags[m_curHdrIndex] & MSG_VIEW_FLAG_DUMMY)
     ++m_curHdrIndex;
 
   nsCOMPtr<nsIMsgDBHdr> nextHdr;
 
   nsresult rv = m_view->GetMsgHdrForViewIndex(m_curHdrIndex++, getter_AddRefs(nextHdr));
-  NS_IF_ADDREF(*aItem = nextHdr);
+  nextHdr.forget(aItem);
   return rv;
 }
 
 NS_IMETHODIMP nsMsgDBView::nsMsgViewHdrEnumerator::HasMoreElements(bool *aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = m_curHdrIndex < m_view->GetSize();
   return NS_OK;
--- a/mailnews/base/src/nsMsgFolderCacheElement.cpp
+++ b/mailnews/base/src/nsMsgFolderCacheElement.cpp
@@ -33,19 +33,16 @@ NS_IMETHODIMP nsMsgFolderCacheElement::S
 {
   m_folderKey = aFolderKey;
   return NS_OK;
 }
 
 void nsMsgFolderCacheElement::SetOwningCache(nsMsgFolderCache *owningCache)
 {
   m_owningCache = owningCache;
-  // circular reference, don't do it.
-  //  if (owningCache)
-  //    NS_ADDREF(owningCache);
 }
 
 NS_IMETHODIMP nsMsgFolderCacheElement::GetStringProperty(const char *propertyName, nsACString& result)
 {
   NS_ENSURE_ARG_POINTER(propertyName);
   NS_ENSURE_TRUE(m_mdbRow && m_owningCache, NS_ERROR_FAILURE);
 
   mdb_token property_token;
--- a/mailnews/base/src/nsMsgFolderDataSource.cpp
+++ b/mailnews/base/src/nsMsgFolderDataSource.cpp
@@ -1086,18 +1086,17 @@ nsMsgFolderDataSource::createServerIsDef
     nsCOMPtr <nsIPop3IncomingServer> pop3Server = do_QueryInterface(incomingServer);
     if (pop3Server)
     {
       nsCString deferredToServer;
       pop3Server->GetDeferredToAccount(deferredToServer);
       isDeferred = !deferredToServer.IsEmpty();
     }
   }
-  *target = (isDeferred) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = isDeferred ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderCanCreateFoldersOnServerNode(nsIMsgFolder* folder,
                                                                  nsIRDFNode **target)
 {
   nsresult rv;
@@ -1105,21 +1104,17 @@ nsMsgFolderDataSource::createFolderCanCr
   nsCOMPtr<nsIMsgIncomingServer> server;
   rv = folder->GetServer(getter_AddRefs(server));
   if (NS_FAILED(rv) || !server) return NS_ERROR_FAILURE;
 
   bool canCreateFoldersOnServer;
   rv = server->GetCanCreateFoldersOnServer(&canCreateFoldersOnServer);
   if (NS_FAILED(rv)) return rv;
 
-  if (canCreateFoldersOnServer)
-    *target = kTrueLiteral;
-  else
-    *target = kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canCreateFoldersOnServer ? kTrueLiteral : kFalseLiteral);
 
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderCanFileMessagesOnServerNode(nsIMsgFolder* folder,
                                                                  nsIRDFNode **target)
 {
@@ -1128,109 +1123,97 @@ nsMsgFolderDataSource::createFolderCanFi
   nsCOMPtr<nsIMsgIncomingServer> server;
   rv = folder->GetServer(getter_AddRefs(server));
   if (NS_FAILED(rv) || !server) return NS_ERROR_FAILURE;
 
   bool canFileMessagesOnServer;
   rv = server->GetCanFileMessagesOnServer(&canFileMessagesOnServer);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (canFileMessagesOnServer) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canFileMessagesOnServer ? kTrueLiteral : kFalseLiteral);
 
   return NS_OK;
 }
 
 
 nsresult
 nsMsgFolderDataSource::createFolderIsServerNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool isServer;
   rv = folder->GetIsServer(&isServer);
   if (NS_FAILED(rv)) return rv;
 
   *target = nullptr;
 
-  if (isServer)
-    *target = kTrueLiteral;
-  else
-    *target = kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = isServer ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderNoSelectNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool noSelect;
   rv = folder->GetNoSelect(&noSelect);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (noSelect) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = noSelect ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createInVFEditSearchScopeNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   bool inVFEditSearchScope = false;
   folder->GetInVFEditSearchScope(&inVFEditSearchScope);
 
-  *target = inVFEditSearchScope ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = inVFEditSearchScope ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderVirtualNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   uint32_t folderFlags;
   folder->GetFlags(&folderFlags);
 
-  *target = (folderFlags & nsMsgFolderFlags::Virtual) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = (folderFlags & nsMsgFolderFlags::Virtual) ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 
 nsresult
 nsMsgFolderDataSource::createFolderImapSharedNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool imapShared;
   rv = folder->GetImapShared(&imapShared);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (imapShared) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = imapShared ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 
 nsresult
 nsMsgFolderDataSource::createFolderSynchronizeNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool sync;
   rv = folder->GetFlag(nsMsgFolderFlags::Offline, &sync);
   if (NS_FAILED(rv)) return rv;
 
-  *target = nullptr;
-
-  *target = (sync) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = sync ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderSyncDisabledNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
 
@@ -1243,19 +1226,20 @@ nsMsgFolderDataSource::createFolderSyncD
 
   rv = folder->GetServer(getter_AddRefs(server));
   if (NS_FAILED(rv) || !server) return NS_ERROR_FAILURE;
 
   nsCString serverType;
   rv = server->GetType(serverType);
   if (NS_FAILED(rv)) return rv;
 
-  *target = isServer || MsgLowerCaseEqualsLiteral(serverType, "none") || MsgLowerCaseEqualsLiteral(serverType, "pop3") ?
-            kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = (isServer || MsgLowerCaseEqualsLiteral(serverType, "none") ||
+                                      MsgLowerCaseEqualsLiteral(serverType, "pop3")) ?
+              kTrueLiteral : kFalseLiteral
+  );
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createCanSearchMessages(nsIMsgFolder* folder,
                                                                  nsIRDFNode **target)
 {
   nsresult rv;
@@ -1263,18 +1247,17 @@ nsMsgFolderDataSource::createCanSearchMe
   nsCOMPtr<nsIMsgIncomingServer> server;
   rv = folder->GetServer(getter_AddRefs(server));
   if (NS_FAILED(rv) || !server) return NS_ERROR_FAILURE;
 
   bool canSearchMessages;
   rv = server->GetCanSearchMessages(&canSearchMessages);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (canSearchMessages) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canSearchMessages ? kTrueLiteral : kFalseLiteral);
 
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderOpenNode(nsIMsgFolder *folder, nsIRDFNode **target)
 {
   NS_ENSURE_ARG_POINTER(target);
@@ -1286,19 +1269,17 @@ nsMsgFolderDataSource::createFolderOpenN
   if (NS_FAILED(rv))
     return NS_RDF_NO_VALUE;
 
   bool closed;
   rv = folder->GetFlag(nsMsgFolderFlags::Elided, &closed);
   if (NS_FAILED(rv))
     return rv;
 
-  *target = (closed) ? kFalseLiteral : kTrueLiteral;
-
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = closed ? kFalseLiteral : kTrueLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderIsSecureNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
@@ -1307,101 +1288,94 @@ nsMsgFolderDataSource::createFolderIsSec
   nsCOMPtr<nsIMsgIncomingServer> server;
   rv = folder->GetServer(getter_AddRefs(server));
 
   if (NS_SUCCEEDED(rv) && server) {
     rv = server->GetIsSecure(&isSecure);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  *target = (isSecure) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = isSecure ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 
 nsresult
 nsMsgFolderDataSource::createFolderCanSubscribeNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool canSubscribe;
   rv = folder->GetCanSubscribe(&canSubscribe);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (canSubscribe) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canSubscribe ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderSupportsOfflineNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool supportsOffline;
   rv = folder->GetSupportsOffline(&supportsOffline);
   NS_ENSURE_SUCCESS(rv,rv);
 
-  *target = (supportsOffline) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = supportsOffline ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderCanFileMessagesNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool canFileMessages;
   rv = folder->GetCanFileMessages(&canFileMessages);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (canFileMessages) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canFileMessages ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderCanCreateSubfoldersNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   nsresult rv;
   bool canCreateSubfolders;
   rv = folder->GetCanCreateSubfolders(&canCreateSubfolders);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (canCreateSubfolders) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canCreateSubfolders ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderCanRenameNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   bool canRename;
   nsresult rv = folder->GetCanRename(&canRename);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (canRename) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canRename ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 nsresult
 nsMsgFolderDataSource::createFolderCanCompactNode(nsIMsgFolder* folder,
                                                   nsIRDFNode **target)
 {
   bool canCompact;
   nsresult rv = folder->GetCanCompact(&canCompact);
   if (NS_FAILED(rv)) return rv;
 
-  *target = (canCompact) ? kTrueLiteral : kFalseLiteral;
-  NS_IF_ADDREF(*target);
+  NS_IF_ADDREF(*target = canCompact ? kTrueLiteral : kFalseLiteral);
   return NS_OK;
 }
 
 
 nsresult
 nsMsgFolderDataSource::createTotalMessagesNode(nsIMsgFolder *folder,
                                                nsIRDFNode **target)
 {
--- a/mailnews/base/src/nsMsgGroupThread.cpp
+++ b/mailnews/base/src/nsMsgGroupThread.cpp
@@ -553,18 +553,17 @@ NS_IMETHODIMP nsMsgGroupThreadEnumerator
   if (mNeedToPrefetch)
     Prefetch();
   *aResult = !mDone;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgGroupThread::EnumerateMessages(nsMsgKey parentKey, nsISimpleEnumerator* *result)
 {
-  nsMsgGroupThreadEnumerator* e = new nsMsgGroupThreadEnumerator(this, parentKey, nullptr, nullptr);
-  NS_ADDREF(*result = e);
+  NS_ADDREF(*result = new nsMsgGroupThreadEnumerator(this, parentKey, nullptr, nullptr));
   return NS_OK;
 }
 
 #if 0
 nsresult nsMsgGroupThread::ReparentMsgsWithInvalidParent(uint32_t numChildren, nsMsgKey threadParentKey)
 {
   nsresult ret = NS_OK;
   // run through looking for messages that don't have a correct parent,
--- a/mailnews/base/src/nsMsgMailSession.cpp
+++ b/mailnews/base/src/nsMsgMailSession.cpp
@@ -483,17 +483,17 @@ nsMsgMailSession::GetDataFilesDir(const 
                              NS_GET_IID(nsIFile),
                              getter_AddRefs(defaultsDir));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = defaultsDir->AppendNative(nsDependentCString(dirName));
   if (NS_SUCCEEDED(rv))
     rv = GetSelectedLocaleDataDir(defaultsDir);
 
-  NS_IF_ADDREF(*dataFilesDir = defaultsDir);
+  defaultsDir.forget(dataFilesDir);
 
   return rv;
 }
 
 /********************************************************************************/
 
 NS_IMPL_ISUPPORTS(nsMsgShutdownService, nsIMsgShutdownService, nsIUrlListener, nsIObserver)
 
--- a/mailnews/base/src/nsMsgOfflineManager.cpp
+++ b/mailnews/base/src/nsMsgOfflineManager.cpp
@@ -50,18 +50,17 @@ nsMsgOfflineManager::nsMsgOfflineManager
 nsMsgOfflineManager::~nsMsgOfflineManager()
 {
 }
 
 /* attribute nsIMsgWindow window; */
 NS_IMETHODIMP nsMsgOfflineManager::GetWindow(nsIMsgWindow * *aWindow)
 {
   NS_ENSURE_ARG(aWindow);
-  *aWindow = m_window;
-  NS_IF_ADDREF(*aWindow);
+  NS_IF_ADDREF(*aWindow = m_window);
   return NS_OK;
 }
 NS_IMETHODIMP nsMsgOfflineManager::SetWindow(nsIMsgWindow * aWindow)
 {
   m_window = aWindow;
   if (m_window)
     m_window->GetStatusFeedback(getter_AddRefs(m_statusFeedback));
   else
--- a/mailnews/base/src/nsMsgQuickSearchDBView.cpp
+++ b/mailnews/base/src/nsMsgQuickSearchDBView.cpp
@@ -44,20 +44,16 @@ NS_IMETHODIMP nsMsgQuickSearchDBView::Op
 
 NS_IMETHODIMP
 nsMsgQuickSearchDBView::CloneDBView(nsIMessenger *aMessengerInstance,
                                     nsIMsgWindow *aMsgWindow,
                                     nsIMsgDBViewCommandUpdater *aCmdUpdater,
                                     nsIMsgDBView **_retval)
 {
   nsMsgQuickSearchDBView* newMsgDBView = new nsMsgQuickSearchDBView();
-
-  if (!newMsgDBView)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_IF_ADDREF(*_retval = newMsgDBView);
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -426,22 +422,22 @@ nsresult nsMsgQuickSearchDBView::GetFirs
   nsCOMPtr<nsIMsgDBHdr> rootParent;
   int32_t rootIndex;
   threadHdr->GetRootHdr(&rootIndex, getter_AddRefs(rootParent));
   if (rootParent)
     rootParent->GetMessageKey(&threadRootKey);
   else
     threadHdr->GetThreadKey(&threadRootKey);
 
-  nsCOMPtr <nsIMsgDBHdr> retHdr;
+  nsCOMPtr<nsIMsgDBHdr> retHdr;
 
   // iterate over thread, finding mgsHdr in view with the lowest level.
   for (uint32_t childIndex = 0; childIndex < numChildren; childIndex++)
   {
-    nsCOMPtr <nsIMsgDBHdr> child;
+    nsCOMPtr<nsIMsgDBHdr> child;
     rv = threadHdr->GetChildHdrAt(childIndex, getter_AddRefs(child));
     if (NS_SUCCEEDED(rv) && child)
     {
       nsMsgKey msgKey;
       child->GetMessageKey(&msgKey);
 
       // this works because we've already sorted m_keys by id.
       nsMsgViewIndex keyIndex = m_origKeys.BinaryIndexOf(msgKey);
@@ -477,17 +473,17 @@ nsresult nsMsgQuickSearchDBView::GetFirs
         if (level < minLevel)
         {
           minLevel = level;
           retHdr = child;
         }
       }
     }
   }
-  NS_IF_ADDREF(*result = retHdr);
+  retHdr.forget(result);
   return NS_OK; 
 }
 
 nsresult nsMsgQuickSearchDBView::SortThreads(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder)
 {
   // don't need to sort by threads for group view.
   if (m_viewFlags & nsMsgViewFlagsType::kGroupBySort)
     return NS_OK;
--- a/mailnews/base/src/nsMsgRDFDataSource.cpp
+++ b/mailnews/base/src/nsMsgRDFDataSource.cpp
@@ -279,18 +279,17 @@ nsMsgRDFDataSource::Observe(nsISupports 
 }
 
 
 NS_IMETHODIMP nsMsgRDFDataSource::GetWindow(nsIMsgWindow * *aWindow)
 {
   if(!aWindow)
     return NS_ERROR_NULL_POINTER;
 
-  *aWindow = mWindow;
-  NS_IF_ADDREF(*aWindow);
+  NS_IF_ADDREF(*aWindow = mWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgRDFDataSource::SetWindow(nsIMsgWindow * aWindow)
 {
   mWindow = aWindow;
   return NS_OK;
 }
--- a/mailnews/base/src/nsMsgRDFUtils.cpp
+++ b/mailnews/base/src/nsMsgRDFUtils.cpp
@@ -19,46 +19,44 @@ nsresult createNode(const char16_t *str,
   if (str) {
     rv = rdfService->GetLiteral(str, getter_AddRefs(value));
   } 
   else {
     rv = rdfService->GetLiteral(EmptyString().get(), getter_AddRefs(value));
   }
 
   if (NS_SUCCEEDED(rv)) {
-    *node = value;
-    NS_IF_ADDREF(*node);
+    value.forget(node);
   }
   return rv;
 }
 
 nsresult createIntNode(int32_t value, nsIRDFNode **node, nsIRDFService *rdfService)
 {
   *node = nullptr;
   nsresult rv; 
   if (!rdfService) return NS_ERROR_NULL_POINTER;  
   nsCOMPtr<nsIRDFInt> num;
   rv = rdfService->GetIntLiteral(value, getter_AddRefs(num));
   if(NS_SUCCEEDED(rv)) {
-    *node = num;
-    NS_IF_ADDREF(*node);
+    num.forget(node);
   }
   return rv;
 }
 
 nsresult createBlobNode(uint8_t *value, uint32_t &length, nsIRDFNode **node, nsIRDFService *rdfService)
 {
   NS_ENSURE_ARG_POINTER(node);
   NS_ENSURE_ARG_POINTER(rdfService);
   
   *node = nullptr;
   nsCOMPtr<nsIRDFBlob> blob;
   nsresult rv = rdfService->GetBlobLiteral(value, length, getter_AddRefs(blob));
   NS_ENSURE_SUCCESS(rv,rv);
-  NS_IF_ADDREF(*node = blob);
+  blob.forget(node);
   return rv;
 }
 
 nsresult GetTargetHasAssertion(nsIRDFDataSource *dataSource, nsIRDFResource* folderResource,
                                nsIRDFResource *property,bool tv, nsIRDFNode *target,bool* hasAssertion)
 {
   NS_ENSURE_ARG_POINTER(hasAssertion);
   
--- a/mailnews/base/src/nsMsgSearchDBView.cpp
+++ b/mailnews/base/src/nsMsgSearchDBView.cpp
@@ -77,20 +77,16 @@ nsMsgSearchDBView::Open(nsIMsgFolder *fo
 
 NS_IMETHODIMP
 nsMsgSearchDBView::CloneDBView(nsIMessenger *aMessengerInstance,
                                nsIMsgWindow *aMsgWindow,
                                nsIMsgDBViewCommandUpdater *aCmdUpdater,
                                nsIMsgDBView **_retval)
 {
   nsMsgSearchDBView* newMsgDBView = new nsMsgSearchDBView();
-
-  if (!newMsgDBView)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv,rv);
 
   NS_IF_ADDREF(*_retval = newMsgDBView);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/mailnews/base/src/nsMsgSpecialViews.cpp
+++ b/mailnews/base/src/nsMsgSpecialViews.cpp
@@ -68,20 +68,16 @@ nsresult nsMsgThreadsWithUnreadDBView::A
     m_totalUnwantedMessagesInView++;
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgThreadsWithUnreadDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
 {
   nsMsgThreadsWithUnreadDBView* newMsgDBView = new nsMsgThreadsWithUnreadDBView();
-
-  if (!newMsgDBView)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv,rv);
 
   NS_IF_ADDREF(*_retval = newMsgDBView);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgThreadsWithUnreadDBView::GetNumMsgsInView(int32_t *aNumMsgs)
@@ -153,20 +149,16 @@ nsresult nsMsgWatchedThreadsWithUnreadDB
   m_totalUnwantedMessagesInView++;
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgWatchedThreadsWithUnreadDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
 {
   nsMsgWatchedThreadsWithUnreadDBView* newMsgDBView = new nsMsgWatchedThreadsWithUnreadDBView();
-
-  if (!newMsgDBView)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv,rv);
 
   NS_IF_ADDREF(*_retval = newMsgDBView);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/mailnews/base/src/nsMsgXFViewThread.cpp
+++ b/mailnews/base/src/nsMsgXFViewThread.cpp
@@ -150,23 +150,25 @@ nsresult nsMsgXFViewThread::AddHdr(nsIMs
         NS_ERROR("how did we get in the wrong thread?");
         parent = nullptr;
       }
       break;
     }
   }
   if (parent)
   {
-    if (outParent)
-      NS_ADDREF(*outParent = parent);
     uint32_t parentLevel = m_levels[parentIndex];
     nsMsgKey parentKey;
     parent->GetMessageKey(&parentKey);
     nsCOMPtr<nsIMsgFolder> parentFolder;
     parent->GetFolder(getter_AddRefs(parentFolder));
+
+    if (outParent)
+      parent.forget(outParent);
+
     // iterate over our parents' children until we find one we're older than,
     // and insert ourselves before it, or as the last child. In other words,
     // insert, sorted by date.
     uint32_t msgDate, childDate;
     newHdr->GetDateInSeconds(&msgDate);
     nsCOMPtr<nsIMsgDBHdr> child;
     nsMsgViewIndex i;
     nsMsgViewIndex insertIndex = m_keys.Length();
@@ -234,17 +236,17 @@ nsresult nsMsgXFViewThread::AddHdr(nsIMs
         m_levels[i] = m_levels[1] + 1;
     }
     else
     {
       m_keys.AppendElement(newHdrKey);
       m_levels.AppendElement(1);
       m_folders.AppendObject(newHdrFolder);
       if (outParent)
-        NS_IF_ADDREF(*outParent = rootHdr);
+        rootHdr.forget(outParent);
       whereInserted = m_keys.Length() -1;
     }
   }
 
   // ### TODO handle the case where the root header starts 
   // with Re, and the new one doesn't, and is earlier. In that
   // case, we want to promote the new header to root.
 
@@ -461,17 +463,17 @@ NS_IMETHODIMP nsMsgXFViewThread::GetFirs
       
       bool isRead;
       nsCOMPtr<nsIMsgDatabase> db;
       nsresult rv = m_folders[childIndex]->GetMsgDatabase(getter_AddRefs(db));
       if (NS_SUCCEEDED(rv))
         rv = db->IsRead(msgKey, &isRead);
       if (NS_SUCCEEDED(rv) && !isRead)
       {
-        NS_ADDREF(*aResult = child);
+        child.forget(aResult);
         break;
       }
     }
   }
   return rv;
 }
 NS_IMETHODIMP nsMsgXFViewThread::EnumerateMessages(nsMsgKey aParentKey,
                                                    nsISimpleEnumerator **aResult)
--- a/mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
+++ b/mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
@@ -58,20 +58,16 @@ NS_IMETHODIMP nsMsgXFVirtualFolderDBView
   return nsMsgSearchDBView::Close();
 }
 
 NS_IMETHODIMP
 nsMsgXFVirtualFolderDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow,
                                         nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
 {
   nsMsgXFVirtualFolderDBView* newMsgDBView = new nsMsgXFVirtualFolderDBView();
-
-  if (!newMsgDBView)
-    return NS_ERROR_OUT_OF_MEMORY;
-
   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
   NS_ENSURE_SUCCESS(rv,rv);
 
   NS_IF_ADDREF(*_retval = newMsgDBView);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/mailnews/base/src/nsSubscribableServer.cpp
+++ b/mailnews/base/src/nsSubscribableServer.cpp
@@ -326,20 +326,17 @@ nsSubscribableServer::SetSubscribeListen
 	mSubscribeListener = aListener;
 	return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSubscribableServer::GetSubscribeListener(nsISubscribeListener **aListener)
 {
 	if (!aListener) return NS_ERROR_NULL_POINTER;
-	if (mSubscribeListener) {
-			*aListener = mSubscribeListener;
-			NS_ADDREF(*aListener);
-	}
+	NS_IF_ADDREF(*aListener = mSubscribeListener);
 	return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSubscribableServer::SubscribeCleanup()
 {
 	NS_ASSERTION(false,"override this.");
 	return NS_ERROR_FAILURE;
--- a/mailnews/base/src/nsSubscribeDataSource.cpp
+++ b/mailnews/base/src/nsSubscribeDataSource.cpp
@@ -156,25 +156,25 @@ nsSubscribeDataSource::GetTarget(nsIRDFR
         
         return childResource->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target);
     }
     else if (property == kNC_Subscribed.get()) {
         bool isSubscribed;
         rv = server->IsSubscribed(relativePath, &isSubscribed);
         NS_ENSURE_SUCCESS(rv,rv);
     
-        NS_IF_ADDREF(*target = (isSubscribed ? kTrueLiteral : kFalseLiteral));
+        NS_IF_ADDREF(*target = isSubscribed ? kTrueLiteral : kFalseLiteral);
         return NS_OK;
     }
     else if (property == kNC_Subscribable.get()) {
         bool isSubscribable;
         rv = server->IsSubscribable(relativePath, &isSubscribable);
         NS_ENSURE_SUCCESS(rv,rv);
-        
-        NS_IF_ADDREF(*target = (isSubscribable ? kTrueLiteral : kFalseLiteral));
+
+        NS_IF_ADDREF(*target = isSubscribable ? kTrueLiteral : kFalseLiteral);
         return NS_OK;
     }
     else if (property == kNC_ServerType.get()) {
         nsCString serverTypeStr;
         rv = GetServerType(server, serverTypeStr);
         NS_ENSURE_SUCCESS(rv,rv);
 
         nsCOMPtr<nsIRDFLiteral> serverType;