Bug 611233. (Bv2a) nsImapService.cpp: Fix 4 crashes reported by bug 412109 (WIP) test, Add 3 additional NS_ENSURE_SUCCESS(rv, rv), plus some nits. r=dbienvenu.
authorSerge Gautherie <sgautherie.bz@free.fr>
Tue, 10 Jan 2012 22:25:37 +0100
changeset 10394 775c1ec9d57661b2293622f4f735aa8e051297c4
parent 10393 6e42a9a28e06d3f17ee17746327914941f44a938
child 10395 9f829c7a28d58b78ca1c0cdaac29460911a3b6a9
push id402
push userbugzilla@standard8.plus.com
push dateTue, 13 Mar 2012 21:17:18 +0000
treeherdercomm-beta@d080a8ebf16a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbienvenu
bugs611233, 412109
Bug 611233. (Bv2a) nsImapService.cpp: Fix 4 crashes reported by bug 412109 (WIP) test, Add 3 additional NS_ENSURE_SUCCESS(rv, rv), plus some nits. r=dbienvenu.
mailnews/imap/src/nsImapService.cpp
mailnews/local/src/nsPop3Service.cpp
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -271,26 +271,24 @@ NS_IMETHODIMP nsImapService::LiteSelectF
   return FolderCommand(aImapMailFolder, aUrlListener,
                        "/liteselect>", nsIImapUrl::nsImapLiteSelectFolder, aMsgWindow, aURL);
 }
 
 NS_IMETHODIMP nsImapService::GetUrlForUri(const char *aMessageURI, 
                                           nsIURI **aURL, 
                                           nsIMsgWindow *aMsgWindow) 
 {
-  nsresult rv = NS_OK;
-
   nsCAutoString messageURI(aMessageURI);
 
   if (messageURI.Find(NS_LITERAL_CSTRING("&type=application/x-message-display")) != kNotFound)
     return NS_NewURI(aURL, aMessageURI);
 
   nsCOMPtr<nsIMsgFolder> folder;
   nsCAutoString msgKey;
-  rv = DecomposeImapURI(messageURI, getter_AddRefs(folder), msgKey);
+  nsresult rv = DecomposeImapURI(messageURI, getter_AddRefs(folder), msgKey);
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsIImapUrl> imapUrl;
     nsCAutoString urlSpec;
     char hierarchyDelimiter = GetHierarchyDelimiter(folder);
     rv = CreateStartOfImapUrl(messageURI, getter_AddRefs(imapUrl), folder, nsnull, urlSpec, hierarchyDelimiter);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = SetImapUrlSink(folder, imapUrl);
@@ -320,17 +318,16 @@ NS_IMETHODIMP nsImapService::GetUrlForUr
 NS_IMETHODIMP nsImapService::OpenAttachment(const char *aContentType, 
                                             const char *aFileName,
                                             const char *aUrl, 
                                             const char *aMessageUri, 
                                             nsISupports *aDisplayConsumer, 
                                             nsIMsgWindow *aMsgWindow, 
                                             nsIUrlListener *aUrlListener)
 {
-  nsresult rv = NS_OK;
   // okay this is a little tricky....we may have to fetch the mime part
   // or it may already be downloaded for us....the only way i can tell to 
   // distinguish the two events is to search for ?section or ?part
   
   nsCAutoString uri(aMessageUri);
   nsCAutoString urlString(aUrl);
   MsgReplaceSubstring(urlString, "/;section", "?section");
   
@@ -358,20 +355,21 @@ NS_IMETHODIMP nsImapService::OpenAttachm
     uri += aContentType;
     uri += "&filename=";
     uri += aFileName;
   }
 
   nsCOMPtr<nsIMsgFolder> folder;
   nsCAutoString msgKey;
   nsCAutoString uriMimePart;
-  nsCAutoString	folderURI;
+  nsCAutoString folderURI;
   nsMsgKey key;
 
-  rv = DecomposeImapURI(uri, getter_AddRefs(folder), msgKey);
+  nsresult rv = DecomposeImapURI(uri, getter_AddRefs(folder), msgKey);
+  NS_ENSURE_SUCCESS(rv, rv);
   rv = nsParseImapMessageURI(uri.get(), folderURI, &key, getter_Copies(uriMimePart));
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsIImapMessageSink> imapMessageSink(do_QueryInterface(folder, &rv));
     if (NS_SUCCEEDED(rv))
     {
       nsCOMPtr<nsIImapUrl> imapUrl;
       nsCAutoString urlSpec;
@@ -409,25 +407,25 @@ NS_IMETHODIMP nsImapService::OpenAttachm
 
 NS_IMETHODIMP nsImapService::FetchMimePart(nsIURI *aURI, 
                                            const char *aMessageURI, 
                                            nsISupports *aDisplayConsumer, 
                                            nsIMsgWindow *aMsgWindow, 
                                            nsIUrlListener *aUrlListener, 
                                            nsIURI **aURL)
 {
-  nsresult rv = NS_OK;
   nsCOMPtr<nsIMsgFolder> folder;
   nsCAutoString messageURI(aMessageURI);
   nsCAutoString msgKey;
   nsCAutoString mimePart;
   nsCAutoString folderURI;
   nsMsgKey key;
   
-  rv = DecomposeImapURI(messageURI, getter_AddRefs(folder), msgKey);
+  nsresult rv = DecomposeImapURI(messageURI, getter_AddRefs(folder), msgKey);
+  NS_ENSURE_SUCCESS(rv, rv);
   rv = nsParseImapMessageURI(aMessageURI, folderURI, &key, getter_Copies(mimePart));
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsIImapMessageSink> imapMessageSink(do_QueryInterface(folder, &rv));
     if (NS_SUCCEEDED(rv))
     {
       nsCOMPtr<nsIImapUrl> imapUrl = do_QueryInterface(aURI);
       nsCOMPtr<nsIMsgMailNewsUrl> msgurl (do_QueryInterface(aURI));
@@ -447,21 +445,22 @@ NS_IMETHODIMP nsImapService::FetchMimePa
 
 NS_IMETHODIMP nsImapService::DisplayMessage(const char *aMessageURI,
                                             nsISupports *aDisplayConsumer,  
                                             nsIMsgWindow *aMsgWindow,
                                             nsIUrlListener *aUrlListener,
                                             const char *aCharsetOverride,
                                             nsIURI **aURL)
 {
-  nsresult rv = NS_OK;
+  nsresult rv;
+
   nsCOMPtr<nsIMsgFolder> folder;
   nsCAutoString msgKey;
   nsCAutoString mimePart;
-  nsCAutoString	folderURI;
+  nsCAutoString folderURI;
   nsMsgKey key;
   nsCAutoString messageURI(aMessageURI);
 
   PRInt32 typeIndex = messageURI.Find("&type=application/x-message-display");
   if (typeIndex != kNotFound)
   {
     // This happens with forward inline of a message/rfc822 attachment opened in
     // a standalone msg window.
@@ -486,16 +485,17 @@ NS_IMETHODIMP nsImapService::DisplayMess
 
       nsCOMPtr<nsISupports> aCtxt = do_QueryInterface(uri);
       //  now try to open the channel passing in our display consumer as the listener
       return aChannel->AsyncOpen(aStreamListener, aCtxt);
     }
   }
 
   rv = DecomposeImapURI(messageURI, getter_AddRefs(folder), msgKey);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (msgKey.IsEmpty())
     return NS_MSG_MESSAGE_NOT_FOUND;
 
   rv = nsParseImapMessageURI(aMessageURI, folderURI, &key, getter_Copies(mimePart));
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsIImapMessageSink> imapMessageSink(do_QueryInterface(folder, &rv));
     if (NS_SUCCEEDED(rv))
@@ -817,26 +817,25 @@ NS_IMETHODIMP nsImapService::CopyMessage
   return rv;
 }
 
 NS_IMETHODIMP nsImapService::Search(nsIMsgSearchSession *aSearchSession, 
                                     nsIMsgWindow *aMsgWindow, 
                                     nsIMsgFolder *aMsgFolder, 
                                     const char *aSearchUri)
 {
-  nsresult rv = NS_OK;
-  nsCAutoString	folderURI;
+  NS_ENSURE_ARG_POINTER(aSearchUri);
 
   nsCOMPtr<nsIImapUrl> imapUrl;
   nsCOMPtr <nsIUrlListener> urlListener = do_QueryInterface(aSearchSession);
-
   nsCAutoString urlSpec;
   char hierarchyDelimiter = GetHierarchyDelimiter(aMsgFolder);
-  rv = CreateStartOfImapUrl(EmptyCString(), getter_AddRefs(imapUrl), 
-                            aMsgFolder, urlListener, urlSpec, hierarchyDelimiter);
+  nsresult rv = CreateStartOfImapUrl(EmptyCString(), getter_AddRefs(imapUrl),
+                                     aMsgFolder, urlListener, urlSpec,
+                                     hierarchyDelimiter);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIMsgMailNewsUrl> msgurl (do_QueryInterface(imapUrl));
 
   msgurl->SetMsgWindow(aMsgWindow);
   msgurl->SetSearchSession(aSearchSession);
   rv = SetImapUrlSink(aMsgFolder, imapUrl);
 
   if (NS_SUCCEEDED(rv))
@@ -888,19 +887,19 @@ nsresult nsImapService::DecomposeImapURI
 // just a helper method to break down imap message URIs....
 nsresult nsImapService::DecomposeImapURI(const nsACString &aMessageURI, 
                                          nsIMsgFolder **aFolder, 
                                          nsMsgKey *aMsgKey)
 {
   NS_ENSURE_ARG_POINTER(aFolder);
   NS_ENSURE_ARG_POINTER(aMsgKey);
   
-  nsresult rv = NS_OK;
   nsCAutoString folderURI;
-  rv = nsParseImapMessageURI(PromiseFlatCString(aMessageURI).get(), folderURI, aMsgKey, nsnull);
+  nsresult rv = nsParseImapMessageURI(PromiseFlatCString(aMessageURI).get(),
+                                      folderURI, aMsgKey, nsnull);
   NS_ENSURE_SUCCESS(rv,rv);
   
   nsCOMPtr <nsIRDFService> rdf = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
   NS_ENSURE_SUCCESS(rv,rv);
   
   nsCOMPtr<nsIRDFResource> res;
   rv = rdf->GetResource(folderURI, getter_AddRefs(res));
   NS_ENSURE_SUCCESS(rv,rv);
@@ -917,22 +916,22 @@ nsresult nsImapService::DecomposeImapURI
 NS_IMETHODIMP nsImapService::SaveMessageToDisk(const char *aMessageURI, 
                                                nsIFile *aFile, 
                                                bool aAddDummyEnvelope, 
                                                nsIUrlListener *aUrlListener, 
                                                nsIURI **aURL,
                                                bool canonicalLineEnding,
                                                nsIMsgWindow *aMsgWindow)
 {
-  nsresult rv = NS_OK;
   nsCOMPtr<nsIMsgFolder> folder;
   nsCOMPtr<nsIImapUrl> imapUrl;
   nsCAutoString msgKey;
 
-  rv = DecomposeImapURI(nsDependentCString(aMessageURI), getter_AddRefs(folder), msgKey);
+  nsresult rv = DecomposeImapURI(nsDependentCString(aMessageURI),
+                                 getter_AddRefs(folder), msgKey);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMsgOffline = false;
 
   if (folder)
     folder->HasMsgOffline(atoi(msgKey.get()), &hasMsgOffline);
 
   nsCAutoString urlSpec;
@@ -966,16 +965,18 @@ NS_IMETHODIMP nsImapService::SaveMessage
 /* imap4://HOST>fetch><UID>>MAILBOXPATH>x */
 /*   'x' is the message UID */
 /* will set the 'SEEN' flag */
 NS_IMETHODIMP nsImapService::AddImapFetchToUrl(nsIURI *aUrl,
                                                nsIMsgFolder *aImapMailFolder,
                                                const nsACString &aMessageIdentifierList,
                                                const nsACString &aAdditionalHeader)
 {
+  NS_ENSURE_ARG_POINTER(aUrl);
+
   nsCAutoString urlSpec;
   aUrl->GetSpec(urlSpec);
 
   char hierarchyDelimiter = GetHierarchyDelimiter(aImapMailFolder);
 
   urlSpec.Append("fetch>UID>");
   urlSpec.Append(hierarchyDelimiter);
 
@@ -1334,26 +1335,26 @@ NS_IMETHODIMP nsImapService::IsMsgInMemC
 
 nsresult nsImapService::CreateStartOfImapUrl(const nsACString &aImapURI, 
                                              nsIImapUrl **imapUrl,
                                              nsIMsgFolder *aImapMailFolder,
                                              nsIUrlListener *aUrlListener,
                                              nsACString &urlSpec, 
                                              char &hierarchyDelimiter)
 {
-  nsresult rv = NS_OK;
+  NS_ENSURE_ARG_POINTER(aImapMailFolder);
+
   nsCString hostname;
   nsCString username;
   nsCString escapedUsername;
 
-  rv = aImapMailFolder->GetHostname(hostname);
+  nsresult rv = aImapMailFolder->GetHostname(hostname);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aImapMailFolder->GetUsername(username);
   NS_ENSURE_SUCCESS(rv, rv);
-
   if (!username.IsEmpty())
     MsgEscapeString(username, nsINetUtil::ESCAPE_XALPHAS, escapedUsername);
 
   PRInt32 port = nsIImapUrl::DEFAULT_IMAP_PORT;
   nsCOMPtr<nsIMsgIncomingServer> server;
   rv = aImapMailFolder->GetServer(getter_AddRefs(server));
   if (NS_SUCCEEDED(rv)) 
   {
@@ -2230,20 +2231,19 @@ nsresult nsImapService::GetImapConnectio
     // the only thing we can do offline is fetch messages.
     // ### TODO - need to look at msg copy, save attachment, etc. when we
     // have offline message bodies.
     aImapUrl->GetImapAction(&imapAction);
     if (imapAction != nsIImapUrl::nsImapMsgFetch && imapAction != nsIImapUrl::nsImapSaveMessageToDisk)
       return NS_MSG_ERROR_OFFLINE;
   }
 
-  nsresult rv = NS_OK;
   nsCOMPtr<nsIMsgIncomingServer> aMsgIncomingServer;
   nsCOMPtr<nsIMsgMailNewsUrl> msgUrl = do_QueryInterface(aImapUrl);
-  rv = msgUrl->GetServer(getter_AddRefs(aMsgIncomingServer));
+  nsresult rv = msgUrl->GetServer(getter_AddRefs(aMsgIncomingServer));
     
   if (aURL)
   {
     nsCOMPtr<nsIURI> msgUrlUri = do_QueryInterface(msgUrl);
     msgUrlUri.swap(*aURL);
   }
 
   if (NS_SUCCEEDED(rv) && aMsgIncomingServer)
@@ -2619,17 +2619,17 @@ NS_IMETHODIMP nsImapService::NewURI(cons
         folder = do_QueryInterface(subFolder, &rv);
       }
       if (NS_SUCCEEDED(rv))
       {
         nsCOMPtr<nsIImapMessageSink> msgSink = do_QueryInterface(folder);
         rv = aImapUrl->SetImapMessageSink(msgSink);
 
         nsCOMPtr<nsIMsgFolder> msgFolder = do_QueryInterface(folder);
-        rv = SetImapUrlSink(msgFolder, aImapUrl);	
+        rv = SetImapUrlSink(msgFolder, aImapUrl);
 
          nsCString messageIdString;
          aImapUrl->GetListOfMessageIds(messageIdString);
          if (!messageIdString.IsEmpty())
         {
           bool useLocalCache = false;
           msgFolder->HasMsgOffline(atoi(messageIdString.get()), &useLocalCache);  
           mailnewsUrl->SetMsgIsInLocalCache(useLocalCache);
@@ -2856,32 +2856,35 @@ NS_IMETHODIMP nsImapService::NewChannel(
   }
   if (NS_SUCCEEDED(rv))
     NS_IF_ADDREF(*aRetVal = channel);
   return rv;
 }
 
 NS_IMETHODIMP nsImapService::SetDefaultLocalPath(nsILocalFile *aPath)
 {
+  NS_ENSURE_ARG_POINTER(aPath);
+
   return NS_SetPersistentFile(PREF_MAIL_ROOT_IMAP_REL, PREF_MAIL_ROOT_IMAP, aPath);
 }       
 
 NS_IMETHODIMP nsImapService::GetDefaultLocalPath(nsILocalFile **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = nsnull;
   
   bool havePref;
   nsCOMPtr<nsILocalFile> localFile;    
   nsresult rv = NS_GetPersistentFile(PREF_MAIL_ROOT_IMAP_REL,
                                      PREF_MAIL_ROOT_IMAP,
                                      NS_APP_IMAP_MAIL_50_DIR,
                                      havePref,
                                      getter_AddRefs(localFile));
-  
+  NS_ENSURE_SUCCESS(rv, rv);
+
   bool exists;
   rv = localFile->Exists(&exists);
   if (NS_SUCCEEDED(rv) && !exists)
     rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
   NS_ENSURE_SUCCESS(rv, rv);
   
   if (!havePref || !exists) 
   {
@@ -2896,26 +2899,28 @@ NS_IMETHODIMP nsImapService::GetDefaultL
 NS_IMETHODIMP nsImapService::GetServerIID(nsIID **aServerIID)
 {
   *aServerIID = new nsIID(NS_GET_IID(nsIImapIncomingServer));
   return NS_OK;
 }
 
 NS_IMETHODIMP nsImapService::GetRequiresUsername(bool *aRequiresUsername)
 {
-	NS_ENSURE_ARG_POINTER(aRequiresUsername);
-	*aRequiresUsername = true;
-	return NS_OK;
+  NS_ENSURE_ARG_POINTER(aRequiresUsername);
+
+  *aRequiresUsername = true;
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsImapService::GetPreflightPrettyNameWithEmailAddress(bool *aPreflightPrettyNameWithEmailAddress)
 {
-	NS_ENSURE_ARG_POINTER(aPreflightPrettyNameWithEmailAddress);
-	*aPreflightPrettyNameWithEmailAddress = true;
-	return NS_OK;
+  NS_ENSURE_ARG_POINTER(aPreflightPrettyNameWithEmailAddress);
+
+  *aPreflightPrettyNameWithEmailAddress = true;
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsImapService::GetCanLoginAtStartUp(bool *aCanLoginAtStartUp)
 {
   NS_ENSURE_ARG_POINTER(aCanLoginAtStartUp);
   *aCanLoginAtStartUp = true;
   return NS_OK;
 }
@@ -3273,25 +3278,24 @@ NS_IMETHODIMP nsImapService::DownloadMes
   return rv;
 }
 
 NS_IMETHODIMP nsImapService::MessageURIToMsgHdr(const char *uri, nsIMsgDBHdr **aRetVal)
 {
   NS_ENSURE_ARG_POINTER(uri);
   NS_ENSURE_ARG_POINTER(aRetVal);
 
-  nsresult rv = NS_OK;
   nsCOMPtr<nsIMsgFolder> folder;
   nsMsgKey msgKey;
-
-  rv = DecomposeImapURI(nsDependentCString(uri), getter_AddRefs(folder), &msgKey);
+  nsresult rv = DecomposeImapURI(nsDependentCString(uri),
+                                 getter_AddRefs(folder), &msgKey);
   NS_ENSURE_SUCCESS(rv,rv);
-
   rv = folder->GetMessageHeader(msgKey, aRetVal);
   NS_ENSURE_SUCCESS(rv,rv);
+
   return NS_OK;
 }
 
 NS_IMETHODIMP nsImapService::PlaybackAllOfflineOperations(nsIMsgWindow *aMsgWindow, 
                                                           nsIUrlListener *aListener, 
                                                           nsISupports **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
--- a/mailnews/local/src/nsPop3Service.cpp
+++ b/mailnews/local/src/nsPop3Service.cpp
@@ -534,31 +534,30 @@ nsPop3Service::SetDefaultLocalPath(nsILo
 }
 
 NS_IMETHODIMP
 nsPop3Service::GetDefaultLocalPath(nsILocalFile ** aResult)
 {
     NS_ENSURE_ARG_POINTER(aResult);
     *aResult = nsnull;
 
-    nsresult rv;
     bool havePref;
     nsCOMPtr<nsILocalFile> localFile;
-    rv = NS_GetPersistentFile(PREF_MAIL_ROOT_POP3_REL,
-                              PREF_MAIL_ROOT_POP3,
-                              NS_APP_MAIL_50_DIR,
-                              havePref,
-                              getter_AddRefs(localFile));
-        if (NS_FAILED(rv)) return rv;
+    nsresult rv = NS_GetPersistentFile(PREF_MAIL_ROOT_POP3_REL,
+                                       PREF_MAIL_ROOT_POP3,
+                                       NS_APP_MAIL_50_DIR,
+                                       havePref,
+                                       getter_AddRefs(localFile));
+    NS_ENSURE_SUCCESS(rv, rv);
 
     bool exists;
     rv = localFile->Exists(&exists);
     if (NS_SUCCEEDED(rv) && !exists)
         rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
-        if (NS_FAILED(rv)) return rv;
+    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);
     return NS_OK;