Bug 1340972 - Part 1: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/compose. r=aceman
authorJorg K <jorgk@jorgk.com>
Tue, 12 Sep 2017 13:40:14 +0200
changeset 29688 c58474b55551716c4b8ad0ea7f39568268741922
parent 29687 c21facbcd3efa8daeaae48fa5b1ab3ad2b5bdb8e
child 29689 7ea1a92f307016b99e0dd879745cf8b0e71c7159
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersaceman
bugs1340972
Bug 1340972 - Part 1: Fix use of NS_ADDREF() and NS_IF_ADDREF() in mailnews/compose. r=aceman
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/compose/src/nsMsgCompFields.cpp
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgComposeParams.cpp
mailnews/compose/src/nsMsgQuote.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsMsgSendLater.cpp
mailnews/compose/src/nsSmtpUrl.cpp
mailnews/compose/src/nsURLFetcher.cpp
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -1355,18 +1355,17 @@ nsMsgAttachmentHandler::UrlExit(nsresult
   return NS_OK;
 }
 
 
 nsresult
 nsMsgAttachmentHandler::GetMimeDeliveryState(nsIMsgSend** _retval)
 {
   NS_ENSURE_ARG(_retval);
-  *_retval = m_mime_delivery_state;
-  NS_IF_ADDREF(*_retval);
+  NS_IF_ADDREF(*_retval = m_mime_delivery_state);
   return NS_OK;
 }
 
 nsresult
 nsMsgAttachmentHandler::SetMimeDeliveryState(nsIMsgSend* mime_delivery_state)
 {
   /*
     Because setting m_mime_delivery_state to null could destroy ourself as
--- a/mailnews/compose/src/nsMsgCompFields.cpp
+++ b/mailnews/compose/src/nsMsgCompFields.cpp
@@ -656,18 +656,17 @@ NS_IMETHODIMP nsMsgCompFields::ConvertBo
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP nsMsgCompFields::GetSecurityInfo(nsISupports ** aSecurityInfo)
 {
   NS_ENSURE_ARG_POINTER(aSecurityInfo);
-  *aSecurityInfo = mSecureCompFields;
-  NS_IF_ADDREF(*aSecurityInfo);
+  NS_IF_ADDREF(*aSecurityInfo = mSecureCompFields);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgCompFields::SetSecurityInfo(nsISupports * aSecurityInfo)
 {
   mSecureCompFields = aSecurityInfo;
   return NS_OK;
 }
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -1738,18 +1738,17 @@ NS_IMETHODIMP
 nsMsgCompose::GetDomWindow(mozIDOMWindowProxy * *aDomWindow)
 {
   NS_IF_ADDREF(*aDomWindow = m_window);
   return NS_OK;
 }
 
 nsresult nsMsgCompose::GetCompFields(nsIMsgCompFields * *aCompFields)
 {
-  *aCompFields = (nsIMsgCompFields*)m_compFields;
-  NS_IF_ADDREF(*aCompFields);
+  NS_IF_ADDREF(*aCompFields = (nsIMsgCompFields*)m_compFields);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgCompose::GetComposeHTML(bool *aComposeHTML)
 {
   *aComposeHTML = m_composeHTML;
   return NS_OK;
 }
@@ -2252,26 +2251,24 @@ nsresult nsMsgCompose::CreateMessage(con
   while (nextUri);
   PR_Free(uriList);
   return rv;
 }
 
 NS_IMETHODIMP nsMsgCompose::GetProgress(nsIMsgProgress **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
-  *_retval = mProgress;
-  NS_IF_ADDREF(*_retval);
+  NS_IF_ADDREF(*_retval = mProgress);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgCompose::GetMessageSend(nsIMsgSend **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
-  *_retval = mMsgSend;
-  NS_IF_ADDREF(*_retval);
+  NS_IF_ADDREF(*_retval = mMsgSend);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgCompose::SetMessageSend(nsIMsgSend* aMsgSend)
 {
   mMsgSend = aMsgSend;
   return NS_OK;
 }
@@ -3853,32 +3850,31 @@ nsMsgComposeSendListener::OnStopCopy(nsr
 
   return rv;
 }
 
 nsresult
 nsMsgComposeSendListener::GetMsgFolder(nsIMsgCompose *compObj, nsIMsgFolder **msgFolder)
 {
   nsresult rv;
-  nsCOMPtr<nsIMsgFolder> aMsgFolder;
   nsCString folderUri;
 
   rv = compObj->GetSavedFolderURI(getter_Copies(folderUri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIRDFService> rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr <nsIRDFResource> resource;
   rv = rdfService->GetResource(folderUri, getter_AddRefs(resource));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  aMsgFolder = do_QueryInterface(resource, &rv);
+  nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(resource, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  NS_IF_ADDREF(*msgFolder = aMsgFolder);
+  folder.forget(msgFolder);
   return rv;
 }
 
 nsresult
 nsMsgComposeSendListener::RemoveCurrentDraftMessage(nsIMsgCompose *compObj, bool calledByCopy)
 {
   nsresult rv;
   nsCOMPtr <nsIMsgCompFields> compFields = nullptr;
--- a/mailnews/compose/src/nsMsgComposeParams.cpp
+++ b/mailnews/compose/src/nsMsgComposeParams.cpp
@@ -102,18 +102,17 @@ NS_IMETHODIMP nsMsgComposeParams::SetHtm
 
 /* attribute nsIMsgCompFields composeFields; */
 NS_IMETHODIMP nsMsgComposeParams::GetComposeFields(nsIMsgCompFields * *aComposeFields)
 {
   NS_ENSURE_ARG_POINTER(aComposeFields);
   
   if (mComposeFields)
   {
-     *aComposeFields = mComposeFields;
-     NS_ADDREF(*aComposeFields);
+     NS_ADDREF(*aComposeFields = mComposeFields);
   }
   else
     *aComposeFields = nullptr;
   return NS_OK;
 }
 NS_IMETHODIMP nsMsgComposeParams::SetComposeFields(nsIMsgCompFields * aComposeFields)
 {
   mComposeFields = aComposeFields;
@@ -136,18 +135,17 @@ NS_IMETHODIMP nsMsgComposeParams::SetBod
 
 /* attribute nsIMsgSendLisneter sendListener; */
 NS_IMETHODIMP nsMsgComposeParams::GetSendListener(nsIMsgSendListener * *aSendListener)
 {
   NS_ENSURE_ARG_POINTER(aSendListener);
   
   if (mSendListener)
   {
-     *aSendListener = mSendListener;
-     NS_ADDREF(*aSendListener);
+     NS_ADDREF(*aSendListener = mSendListener);
   }
   else
     *aSendListener = nullptr;
   return NS_OK;
 }
 NS_IMETHODIMP nsMsgComposeParams::SetSendListener(nsIMsgSendListener * aSendListener)
 {
   mSendListener = aSendListener;
--- a/mailnews/compose/src/nsMsgQuote.cpp
+++ b/mailnews/compose/src/nsMsgQuote.cpp
@@ -44,18 +44,17 @@ NS_IMETHODIMP nsMsgQuoteListener::SetMsg
 }
 
 NS_IMETHODIMP nsMsgQuoteListener::GetMsgQuote(nsIMsgQuote ** aMsgQuote)
 {
   nsresult rv = NS_OK;
   if (aMsgQuote)
   {
     nsCOMPtr<nsIMsgQuote> msgQuote = do_QueryReferent(mMsgQuote);
-    *aMsgQuote = msgQuote;
-    NS_IF_ADDREF(*aMsgQuote);
+    msgQuote.forget(aMsgQuote);
   }
   else
     rv = NS_ERROR_NULL_POINTER;
 
   return rv;
 }
 
 nsresult nsMsgQuoteListener::OnHeadersReady(nsIMimeHeaders * headers)
@@ -86,18 +85,17 @@ nsMsgQuote::~nsMsgQuote()
 
 NS_IMPL_ISUPPORTS(nsMsgQuote, nsIMsgQuote, nsISupportsWeakReference)
 
 NS_IMETHODIMP nsMsgQuote::GetStreamListener(nsIMsgQuotingOutputStreamListener ** aStreamListener)
 {
   nsresult rv = NS_OK;
   if (aStreamListener)
   {
-    *aStreamListener = mStreamListener;
-    NS_IF_ADDREF(*aStreamListener);
+    NS_IF_ADDREF(*aStreamListener = mStreamListener);
   }
   else
     rv = NS_ERROR_NULL_POINTER;
 
   return rv;
 }
 
 nsresult
@@ -204,22 +202,20 @@ nsMsgQuote::QuoteMessage(const char *msg
   return rv;
 }
 
 NS_IMETHODIMP
 nsMsgQuote::GetQuoteListener(nsIMimeStreamConverterListener** aQuoteListener)
 {
     if (!aQuoteListener || !mQuoteListener)
         return NS_ERROR_NULL_POINTER;
-    *aQuoteListener = mQuoteListener;
-    NS_ADDREF(*aQuoteListener);
+    NS_ADDREF(*aQuoteListener = mQuoteListener);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgQuote::GetQuoteChannel(nsIChannel** aQuoteChannel)
 {
     if (!aQuoteChannel || !mQuoteChannel)
         return NS_ERROR_NULL_POINTER;
-    *aQuoteChannel = mQuoteChannel;
-    NS_ADDREF(*aQuoteChannel);
+    NS_ADDREF(*aQuoteChannel = mQuoteChannel);
     return NS_OK;
 }
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -368,17 +368,17 @@ nsresult nsMsgComposeAndSend::GetNotific
     nsCOMPtr<nsIInterfaceRequestor> notificationCallbacks;
     msgWindow->GetNotificationCallbacks(getter_AddRefs(notificationCallbacks));
     if (notificationCallbacks) {
       nsCOMPtr<nsIInterfaceRequestor> aggregrateIR;
       MsgNewInterfaceRequestorAggregation(notificationCallbacks, ir, getter_AddRefs(aggregrateIR));
       ir = aggregrateIR;
     }
     if (ir) {
-      NS_ADDREF(*aCallbacks = ir);
+      ir.forget(aCallbacks);
       return NS_OK;
     }
   }
   return NS_ERROR_FAILURE;
 }
 
 
 static char *mime_mailto_stream_read_buffer = 0;
@@ -5053,30 +5053,28 @@ nsMsgComposeAndSend::GetSendBodyType(nsA
     aBodyType.Assign(nsDependentCString(m_attachment1_type));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgComposeAndSend::GetIdentity(nsIMsgIdentity **aIdentity)
 {
   NS_ENSURE_ARG_POINTER(aIdentity);
-  *aIdentity = mUserIdentity;
-  NS_IF_ADDREF(*aIdentity);
+  NS_IF_ADDREF(*aIdentity = mUserIdentity);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgComposeAndSend::GetAttachment(uint32_t aIndex,
                                    nsIMsgAttachmentHandler **aAttachment)
 {
   NS_ENSURE_ARG_POINTER(aAttachment);
   if (aIndex >= m_attachment_count)
     return NS_ERROR_ILLEGAL_VALUE;
-  *aAttachment = m_attachments[aIndex];
-  NS_IF_ADDREF(*aAttachment);
+  NS_IF_ADDREF(*aAttachment = m_attachments[aIndex]);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgComposeAndSend::SetSavedToFolderName(const nsAString& aName)
 {
   mSavedToFolderName.Assign(aName);
   return NS_OK;
--- a/mailnews/compose/src/nsMsgSendLater.cpp
+++ b/mailnews/compose/src/nsMsgSendLater.cpp
@@ -1417,17 +1417,17 @@ nsMsgSendLater::GetIdentityFromKey(const
         lookupIdentity = do_QueryElementAt(identities, i, &rv);
         if (NS_FAILED(rv))
           continue;
 
         nsCString key;
         lookupIdentity->GetKey(key);
         if (key.Equals(aKey))
         {
-          NS_IF_ADDREF(*aIdentity = lookupIdentity);
+          lookupIdentity.forget(aIdentity);
           return NS_OK;
         }
       }
     }
   }
 
   // if no aKey, or we failed to find the identity from the key
   // use the identity from the default account.
--- a/mailnews/compose/src/nsSmtpUrl.cpp
+++ b/mailnews/compose/src/nsSmtpUrl.cpp
@@ -737,18 +737,17 @@ nsSmtpUrl::GetDsnEnvid(nsACString &aDsnE
     aDsnEnvid = m_dsnEnvid;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::GetSenderIdentity(nsIMsgIdentity **aSenderIdentity)
 {
   NS_ENSURE_ARG_POINTER(aSenderIdentity);
-  *aSenderIdentity = m_senderIdentity;
-  NS_ADDREF(*aSenderIdentity);
+  NS_ADDREF(*aSenderIdentity = m_senderIdentity);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::SetSenderIdentity(nsIMsgIdentity *aSenderIdentity)
 {
   NS_ENSURE_ARG_POINTER(aSenderIdentity);
   m_senderIdentity = aSenderIdentity;
@@ -763,66 +762,62 @@ nsSmtpUrl::SetPrompt(nsIPrompt *aNetProm
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::GetPrompt(nsIPrompt **aNetPrompt)
 {
     NS_ENSURE_ARG_POINTER(aNetPrompt);
     NS_ENSURE_TRUE(m_netPrompt, NS_ERROR_NULL_POINTER);
-    *aNetPrompt = m_netPrompt;
-    NS_ADDREF(*aNetPrompt);
+    NS_ADDREF(*aNetPrompt = m_netPrompt);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::SetAuthPrompt(nsIAuthPrompt *aNetAuthPrompt)
 {
     NS_ENSURE_ARG_POINTER(aNetAuthPrompt);
     m_netAuthPrompt = aNetAuthPrompt;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::GetAuthPrompt(nsIAuthPrompt **aNetAuthPrompt)
 {
     NS_ENSURE_ARG_POINTER(aNetAuthPrompt);
     NS_ENSURE_TRUE(m_netAuthPrompt, NS_ERROR_NULL_POINTER);
-    *aNetAuthPrompt = m_netAuthPrompt;
-    NS_ADDREF(*aNetAuthPrompt);
+    NS_ADDREF(*aNetAuthPrompt = m_netAuthPrompt);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
 {
     NS_ENSURE_ARG_POINTER(aCallbacks);
     m_callbacks = aCallbacks;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::GetNotificationCallbacks(nsIInterfaceRequestor** aCallbacks)
 {
     NS_ENSURE_ARG_POINTER(aCallbacks);
     NS_ENSURE_TRUE(m_callbacks, NS_ERROR_NULL_POINTER);
-    *aCallbacks = m_callbacks;
-    NS_ADDREF(*aCallbacks);
+    NS_ADDREF(*aCallbacks = m_callbacks);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::SetSmtpServer(nsISmtpServer * aSmtpServer)
 {
     NS_ENSURE_ARG_POINTER(aSmtpServer);
     m_smtpServer = aSmtpServer;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSmtpUrl::GetSmtpServer(nsISmtpServer ** aSmtpServer)
 {
     NS_ENSURE_ARG_POINTER(aSmtpServer);
     NS_ENSURE_TRUE(m_smtpServer, NS_ERROR_NULL_POINTER);
-    *aSmtpServer = m_smtpServer;
-    NS_ADDREF(*aSmtpServer);
+    NS_ADDREF(*aSmtpServer = m_smtpServer);
     return NS_OK;
 }
--- a/mailnews/compose/src/nsURLFetcher.cpp
+++ b/mailnews/compose/src/nsURLFetcher.cpp
@@ -149,18 +149,17 @@ NS_IMETHODIMP
 nsURLFetcher::SetParentContentListener(nsIURIContentListener* aParent)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsURLFetcher::GetLoadCookie(nsISupports ** aLoadCookie)
 {
-  *aLoadCookie = mLoadCookie;
-  NS_IF_ADDREF(*aLoadCookie);
+  NS_IF_ADDREF(*aLoadCookie = mLoadCookie);
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsURLFetcher::SetLoadCookie(nsISupports * aLoadCookie)
 {
   // Remove the DocShell as a listener of the old WebProgress...
   if (mLoadCookie)