Bug 1368786 - release m_mdbRow in hash table entry and also in DTOR. r=rkent
authorJorg K <jorgk@jorgk.com>
Fri, 15 Sep 2017 00:31:04 +0200
changeset 29713 a0bd8f2b70bef081d138819a6363a1917da55cbe
parent 29712 fbadefb10f455bb1b6eeede383fc88e7ca802543
child 29714 254747a8daa5e96faeb4f3c389841e61365cb82b
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersrkent
bugs1368786
Bug 1368786 - release m_mdbRow in hash table entry and also in DTOR. r=rkent
mailnews/db/msgdb/src/nsMsgDatabase.cpp
mailnews/db/msgdb/src/nsMsgHdr.cpp
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -646,16 +646,21 @@ void nsMsgDatabase::AddHdrToUseCache(nsM
 {
   if (key == nsMsgKey_None)
     hdr->GetMessageKey(&key);
   m_headersInUse.Put(key, hdr);
 }
 
 void nsMsgDatabase::ClearUseHdrCache()
 {
+  // Clear out m_mdbRow member variable - the db is going away, which means
+  // that this member variable might very well point to a mork db that is gone.
+  for (auto iter = m_headersInUse.ConstIter(); !iter.Done(); iter.Next()) {
+    NS_IF_RELEASE(iter.Data()->m_mdbRow);
+  }
   m_headersInUse.Clear();
 }
 
 void nsMsgDatabase::RemoveHdrFromUseCache(nsMsgHdr *hdr, nsMsgKey key)
 {
   if (key == nsMsgKey_None)
     hdr->GetMessageKey(&key);
 
--- a/mailnews/db/msgdb/src/nsMsgHdr.cpp
+++ b/mailnews/db/msgdb/src/nsMsgHdr.cpp
@@ -98,16 +98,17 @@ nsresult nsMsgHdr::InitFlags()
   }
 
   return err;
 
 }
 
 nsMsgHdr::~nsMsgHdr()
 {
+  NS_IF_RELEASE(m_mdbRow);
   if (m_mdb)
     m_mdb->RemoveHdrFromUseCache(this, m_messageKey);
   NS_IF_RELEASE(m_mdb);
 }
 
 NS_IMETHODIMP nsMsgHdr::GetMessageKey(nsMsgKey *result)
 {
   if (m_messageKey == nsMsgKey_None && m_mdbRow != nullptr)