Bug 1340972 - Part 6: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/build+extensions+mapi+mime. r=aceman
authorJorg K <jorgk@jorgk.com>
Tue, 12 Sep 2017 22:48:35 +0200
changeset 29696 827578490366dd5b56b20866144ffc31613da0d3
parent 29695 3365d035c78dafad410c222e25a511e35409f2a5
child 29697 309b9671d6a51c6756bc5b9e772cbceba423feb4
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersaceman
bugs1340972
Bug 1340972 - Part 6: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/build+extensions+mapi+mime. r=aceman
mailnews/build/nsMailModule.cpp
mailnews/extensions/fts3/src/nsGlodaRankerFunction.cpp
mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp
mailnews/extensions/smime/src/nsSMimeJSHelper.cpp
mailnews/mapi/mapihook/src/msgMapiHook.cpp
mailnews/mime/emitters/nsMimeHtmlEmitter.cpp
mailnews/mime/src/mimedrft.cpp
mailnews/mime/src/nsCMS.cpp
mailnews/mime/src/nsStreamConverter.cpp
--- a/mailnews/build/nsMailModule.cpp
+++ b/mailnews/build/nsMailModule.cpp
@@ -799,21 +799,19 @@ static nsresult nsVCardMimeContentTypeHa
     return rv;
   }
   *aResult = NULL;
   if (NULL != aOuter)
   {
     rv = NS_ERROR_NO_AGGREGATION;
     return rv;
   }
-  inst = new nsMimeContentTypeHandler("text/x-vcard", &MIME_VCardCreateContentTypeHandlerClass);
-  if (inst == NULL)
-    return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(inst);
+  NS_ADDREF(inst = new nsMimeContentTypeHandler(
+                   "text/x-vcard", &MIME_VCardCreateContentTypeHandlerClass));
   rv = inst->QueryInterface(aIID,aResult);
   NS_RELEASE(inst);
 
   return rv;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // PGP/MIME factories
--- a/mailnews/extensions/fts3/src/nsGlodaRankerFunction.cpp
+++ b/mailnews/extensions/fts3/src/nsGlodaRankerFunction.cpp
@@ -103,11 +103,11 @@ nsGlodaRankerFunction::OnFunctionCall(mo
   }
 #endif
 
   nsCOMPtr<nsIWritableVariant> result = new nsVariant();
    
   rv = result->SetAsDouble(score);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  NS_ADDREF(*_result = result);
+  result.forget(_result);
   return NS_OK;
 }
--- a/mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp
+++ b/mailnews/extensions/mailviews/src/nsMsgMailViewList.cpp
@@ -115,17 +115,17 @@ NS_IMETHODIMP nsMsgMailView::AppendTerm(
 
     return mViewSearchTerms->AppendElement(aTerm, /* weak */ false);
 }
 
 NS_IMETHODIMP nsMsgMailView::CreateTerm(nsIMsgSearchTerm **aResult)
 {
     NS_ENSURE_ARG_POINTER(aResult);
     nsCOMPtr<nsIMsgSearchTerm> searchTerm = do_CreateInstance("@mozilla.org/messenger/searchTerm;1");
-    NS_IF_ADDREF(*aResult = searchTerm);
+    searchTerm.forget(aResult);
     return NS_OK;
 }
 
 /////////////////////////////////////////////////////////////////////////////
 // nsMsgMailViewList implementation
 /////////////////////////////////////////////////////////////////////////////
 nsMsgMailViewList::nsMsgMailViewList()
 {
@@ -175,21 +175,17 @@ NS_IMETHODIMP nsMsgMailViewList::RemoveM
 
     m_mailViews.RemoveElement(aMailView);
     return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailViewList::CreateMailView(nsIMsgMailView ** aMailView)
 {
     NS_ENSURE_ARG_POINTER(aMailView);
-
-    nsMsgMailView * mailView = new nsMsgMailView;
-    NS_ENSURE_TRUE(mailView, NS_ERROR_OUT_OF_MEMORY);
-
-    NS_IF_ADDREF(*aMailView = mailView);
+    NS_ADDREF(*aMailView = new nsMsgMailView);
     return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailViewList::Save()
 {
     // brute force...remove all the old filters in our filter list, then we'll re-add our current
     // list
     nsCOMPtr<nsIMsgFilter> msgFilter;
--- a/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp
+++ b/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp
@@ -112,21 +112,20 @@ NS_IMETHODIMP nsSMimeJSHelper::GetRecipi
 
         nsCString email_lowercase;
         ToLowerCase(email, email_lowercase);
 
         nsCOMPtr<nsIX509Cert> cert;
         if (NS_SUCCEEDED(certdb->FindCertByEmailAddress(
                            email_lowercase, getter_AddRefs(cert))))
         {
-          *iCert = cert;
-          NS_ADDREF(*iCert);
+          cert.forget(iCert);
 
           nsCOMPtr<nsIX509CertValidity> validity;
-          rv = cert->GetValidity(getter_AddRefs(validity));
+          rv = (*iCert)->GetValidity(getter_AddRefs(validity));
 
           if (NS_SUCCEEDED(rv)) {
             nsString id, ed;
 
             if (NS_SUCCEEDED(validity->GetNotBeforeLocalDay(id)))
             {
               *iCII = ToNewUnicode(id);
               if (!*iCII) {
--- a/mailnews/mapi/mapihook/src/msgMapiHook.cpp
+++ b/mailnews/mapi/mapihook/src/msgMapiHook.cpp
@@ -100,22 +100,17 @@ private:
 };
 
 
 NS_IMPL_ISUPPORTS(nsMAPISendListener, nsIMsgSendListener)
 
 nsresult nsMAPISendListener::CreateMAPISendListener( nsIMsgSendListener **ppListener)
 {
     NS_ENSURE_ARG_POINTER(ppListener) ;
-
-    *ppListener = new nsMAPISendListener();
-    if (! *ppListener)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ADDREF(*ppListener);
+    NS_ADDREF(*ppListener = new nsMAPISendListener());
     return NS_OK;
 }
 
 bool nsMapiHook::isMapiService = false;
 
 void nsMapiHook::CleanUp()
 {
     // This routine will be fully implemented in future
--- a/mailnews/mime/emitters/nsMimeHtmlEmitter.cpp
+++ b/mailnews/mime/emitters/nsMimeHtmlEmitter.cpp
@@ -149,18 +149,17 @@ nsMimeHtmlDisplayEmitter::GetHeaderSink(
           msgurl->GetMsgWindow(getter_AddRefs(msgWindow));
           if (msgWindow)
             msgWindow->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
         }
       }
     }
   }
 
-  *aHeaderSink = mHeaderSink;
-  NS_IF_ADDREF(*aHeaderSink);
+  NS_IF_ADDREF(*aHeaderSink = mHeaderSink);
   return rv;
 }
 
 nsresult nsMimeHtmlDisplayEmitter::BroadcastHeaders(nsIMsgHeaderSink * aHeaderSink, int32_t aHeaderMode, bool aFromNewsgroup)
 {
   // two string enumerators to pass out to the header sink
   RefPtr<nsMimeStringEnumerator> headerNameEnumerator = new nsMimeStringEnumerator();
   NS_ENSURE_TRUE(headerNameEnumerator, NS_ERROR_OUT_OF_MEMORY);
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -412,18 +412,17 @@ CreateCompositionFields(const char      
     cFields->SetPriority(priorityName.get());
   }
 
   if (newspost_url) {
     MIME_DecodeMimeHeader(newspost_url, charset, false, true, val);
     cFields->SetNewspostUrl(!val.IsEmpty() ? val.get() : newspost_url);
   }
 
-  *_retval = cFields;
-  NS_IF_ADDREF(*_retval);
+  cFields.forget(_retval);
 
   return rv;
 }
 
 static int
 dummy_file_write(char *buf, int32_t size, void *fileHandle)
 {
   if (!fileHandle)
--- a/mailnews/mime/src/nsCMS.cpp
+++ b/mailnews/mime/src/nsCMS.cpp
@@ -856,18 +856,17 @@ NS_IMETHODIMP nsCMSDecoder::Finish(nsICM
   cmsMsg = NSS_CMSDecoder_Finish(m_dcx);
   m_dcx = nullptr;
   if (cmsMsg) {
     nsCMSMessage *obj = new nsCMSMessage(cmsMsg);
     // The NSS object cmsMsg still carries a reference to the context
     // we gave it on construction.
     // Make sure the context will live long enough.
     obj->referenceContext(m_ctx);
-    *aCMSMsg = obj;
-    NS_ADDREF(*aCMSMsg);
+    NS_ADDREF(*aCMSMsg = obj);
   }
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(nsCMSEncoder, nsICMSEncoder)
 
 nsCMSEncoder::nsCMSEncoder()
 : m_ecx(nullptr)
--- a/mailnews/mime/src/nsStreamConverter.cpp
+++ b/mailnews/mime/src/nsStreamConverter.cpp
@@ -798,22 +798,19 @@ nsStreamConverter::SetForwardInlineFilte
   mForwardInlineFilter = aForwardInlineFilter;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStreamConverter::GetIdentity(nsIMsgIdentity * *aIdentity)
 {
   if (!aIdentity) return NS_ERROR_NULL_POINTER;
-  /*
-  We don't have an identity for the local folders account,
-    we will return null but it is not an error!
-  */
-    *aIdentity = mIdentity;
-    NS_IF_ADDREF(*aIdentity);
+  // We don't have an identity for the local folders account,
+  // we will return null but it is not an error!
+  NS_IF_ADDREF(*aIdentity = mIdentity);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStreamConverter::SetIdentity(nsIMsgIdentity * aIdentity)
 {
   mIdentity = aIdentity;
   return NS_OK;