Bug 797710, keep record of completed release in nsMsgFilterAfterTheFact, r=neil, a=rkent
authorR Kent James <rkent@caspia.com>
Mon, 07 Sep 2015 18:23:26 -0700
changeset 22881 2fc38551ba84f838836dfd8e78f5263cc736c2a9
parent 22880 f23b301607b51e7d019b06d7792e30eecb418e5e
child 22882 722eb27dc2477059bd9210b31cc45b1438402d99
push id1464
push userkent@caspia.com
push dateMon, 14 Sep 2015 21:12:19 +0000
treeherdercomm-beta@166d8e44fb95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil, rkent
bugs797710
Bug 797710, keep record of completed release in nsMsgFilterAfterTheFact, r=neil, a=rkent
mailnews/base/search/src/nsMsgFilterService.cpp
--- a/mailnews/base/search/src/nsMsgFilterService.cpp
+++ b/mailnews/base/search/src/nsMsgFilterService.cpp
@@ -312,16 +312,17 @@ protected:
   uint32_t                    m_numFolders;
   nsTArray<nsMsgKey>          m_searchHits;
   nsCOMPtr<nsIMutableArray>   m_searchHitHdrs;
   nsTArray<nsMsgKey>          m_stopFiltering;
   nsCOMPtr<nsIMsgSearchSession> m_searchSession;
   nsCOMPtr<nsIMsgOperationListener> m_callback;
   uint32_t                    m_nextAction; // next filter action to perform
   nsresult                    mFinalResult; // report of overall success or failure
+  bool                        mNeedsRelease; // Did we need to release ourself?
 };
 
 NS_IMPL_ISUPPORTS(nsMsgFilterAfterTheFact, nsIUrlListener, nsIMsgSearchNotify, nsIMsgCopyServiceListener)
 
 nsMsgFilterAfterTheFact::nsMsgFilterAfterTheFact(nsIMsgWindow *aMsgWindow,
                                                  nsIMsgFilterList *aFilterList,
                                                  nsIArray *aFolderList,
                                                  nsIMsgOperationListener *aCallback)
@@ -329,16 +330,17 @@ nsMsgFilterAfterTheFact::nsMsgFilterAfte
   m_curFilterIndex = m_curFolderIndex = m_nextAction = 0;
   m_msgWindow = aMsgWindow;
   m_filters = aFilterList;
   m_folders = aFolderList;
   m_filters->GetFilterCount(&m_numFilters);
   m_folders->GetLength(&m_numFolders);
 
   NS_ADDREF(this); // we own ourselves, and will release ourselves when execution is done.
+  mNeedsRelease = true;
 
   m_searchHitHdrs = do_CreateInstance(NS_ARRAY_CONTRACTID);
   m_callback = aCallback;
   mFinalResult = NS_OK;
 }
 
 nsMsgFilterAfterTheFact::~nsMsgFilterAfterTheFact()
 {
@@ -352,17 +354,22 @@ nsresult nsMsgFilterAfterTheFact::OnEndE
 
   if (m_filters)
     (void)m_filters->FlushLogIfNecessary();
 
   if (m_callback)
     (void)m_callback->OnStopOperation(mFinalResult);
 
   nsresult rv = mFinalResult;
-  Release(); // release ourselves.
+  MOZ_ASSERT(mNeedsRelease, "OnEndExecution called a second time");
+  if (mNeedsRelease)
+  {
+    Release(); // release ourselves.
+    mNeedsRelease = false;
+  }
   return rv;
 }
 
 nsresult nsMsgFilterAfterTheFact::RunNextFilter()
 {
   nsresult rv = NS_OK;
   while (true)
   {