Bug 617946 - crash in nsImapMailFolder::GetDatabase() with null database, r=aceman a=jorgk
authorR Kent James <rkent@caspia.com>
Wed, 20 Apr 2016 16:22:34 -0700
changeset 27000 820389b55d0dd4b32012aa72e9d03d0bdcf828e4
parent 26999 b300d9fbca1a5cd4366d524ddbc99e99df093134
child 27001 9a02557da4353c3e6d68907263446401c2f1d5d2
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman, jorgk
bugs617946
Bug 617946 - crash in nsImapMailFolder::GetDatabase() with null database, r=aceman a=jorgk
mailnews/db/msgdb/src/nsMsgDatabase.cpp
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -385,17 +385,25 @@ NS_IMETHODIMP nsMsgDBService::CreateNewD
   
   nsCOMPtr <nsIMsgDatabase> msgDB = do_CreateInstance(dbContractID.get(), &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsMsgDatabase *msgDatabase = static_cast<nsMsgDatabase *>(msgDB.get());
 
   msgDatabase->m_folder = aFolder;
   rv = msgDatabase->Open(this, summaryFilePath, true, true);
-  NS_ENSURE_TRUE(rv == NS_MSG_ERROR_FOLDER_SUMMARY_MISSING, rv);
+
+  // We are trying to create a new database, but that implies that it did not
+  // already exist. Open returns NS_MSG_ERROR_FOLDER_SUMMARY_MISSING for the
+  // successful creation of a new database. But if it existed for some
+  // reason, then we would get rv = NS_OK instead. That is a "failure"
+  // from our perspective, so we want to return a failure since we are not
+  // returning a valid database object.
+  NS_ENSURE_TRUE(rv == NS_MSG_ERROR_FOLDER_SUMMARY_MISSING,
+                 NS_SUCCEEDED(rv) ? NS_ERROR_FILE_ALREADY_EXISTS : rv);
 
   NS_ADDREF(*_retval = msgDB);
 
   HookupPendingListeners(msgDB, aFolder);
 
   msgDatabase->RememberLastUseTime();
 
   return NS_OK;