Bug 1368786 - release m_mdbRow in hash table entry and also in DTOR. r=rkent a=jorgk
authorJorg K <jorgk@jorgk.com>
Fri, 15 Sep 2017 00:31:04 +0200
changeset 28604 8cb3077054c23c5590469eafd25f1e5c78db2f4c
parent 28603 122a757d2f7a5594c909958320c463581766bd8b
child 28605 7b6daa02a908409623dccd98f9ca63fc1ed34500
push idunknown
push userunknown
push dateunknown
reviewersrkent, jorgk
bugs1368786
Bug 1368786 - release m_mdbRow in hash table entry and also in DTOR. r=rkent a=jorgk
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)