Bug 646901 - add error checking to fix crash in nsMsgXFVirtualFolderDBView::OnSearchHit(). r=jorgk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Fri, 28 Sep 2018 14:35:12 +0300
changeset 33259 cac40c2c829de36bcc009a375ba950753802dc90
parent 33258 2727ba9a62aa40c4eef3eea56ea8ca21b7555900
child 33260 4568dcf1dd5700335d893b7ce077eabf085f013e
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs646901
Bug 646901 - add error checking to fix crash in nsMsgXFVirtualFolderDBView::OnSearchHit(). r=jorgk dbToUse was null
mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
--- a/mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
+++ b/mailnews/base/src/nsMsgXFVirtualFolderDBView.cpp
@@ -275,38 +275,39 @@ nsMsgXFVirtualFolderDBView::UpdateCacheA
 }
 NS_IMETHODIMP
 nsMsgXFVirtualFolderDBView::OnSearchHit(nsIMsgDBHdr* aMsgHdr,
                                         nsIMsgFolder *aFolder)
 {
   NS_ENSURE_ARG(aMsgHdr);
   NS_ENSURE_ARG(aFolder);
 
-  nsCOMPtr<nsIMsgDatabase> dbToUse;
-  nsCOMPtr<nsIDBFolderInfo> folderInfo;
-  aFolder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(dbToUse));
-
   if (m_curFolderGettingHits != aFolder && m_doingSearch && !m_doingQuickSearch)
   {
     m_curFolderHasCachedHits = false;
     // Since we've gotten a hit for a new folder, the searches for
     // any previous folders are done, so deal with stale cached hits
     // for those folders now.
     UpdateCacheAndViewForPrevSearchedFolders(aFolder);
     m_curFolderGettingHits = aFolder;
     m_hdrHits.Clear();
     m_curFolderStartKeyIndex = m_keys.Length();
   }
 
   bool hdrInCache = false;
-  nsCString searchUri;
   if (!m_doingQuickSearch)
   {
-    m_viewFolder->GetURI(searchUri);
-    dbToUse->HdrIsInCache(searchUri.get(), aMsgHdr, &hdrInCache);
+    nsCOMPtr<nsIMsgDatabase> dbToUse;
+    nsCOMPtr<nsIDBFolderInfo> dummyInfo;
+    nsresult rv = aFolder->GetDBFolderInfoAndDB(getter_AddRefs(dummyInfo), getter_AddRefs(dbToUse));
+    if (NS_SUCCEEDED(rv)) {
+      nsCString searchUri;
+      m_viewFolder->GetURI(searchUri);
+      dbToUse->HdrIsInCache(searchUri.get(), aMsgHdr, &hdrInCache);
+    }
   }
 
   if (!m_doingSearch || !m_curFolderHasCachedHits || !hdrInCache)
   {
     if (m_viewFlags & nsMsgViewFlagsType::kGroupBySort)
       nsMsgGroupView::OnNewHeader(aMsgHdr, nsMsgKey_None, true);
     else if (m_sortValid)
       InsertHdrFromFolder(aMsgHdr, aFolder);