Bug 1138770 - Make memory reporters that have been stashed for testing eligible for unregistration. r=mccr8.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 02 Mar 2015 18:55:42 -0800
changeset 231530 655ddeba3c94b011be1816855d3984e1170346e8
parent 231529 c964a0be6c594e97884f37269dfd48d1aa9a4223
child 231531 d46dcd6bc7e7d66e407e4b4de8b5a2e452da3922
push id28353
push usercbook@mozilla.com
push dateTue, 03 Mar 2015 12:54:59 +0000
treeherdermozilla-central@985070813323 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1138770
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1138770 - Make memory reporters that have been stashed for testing eligible for unregistration. r=mccr8.
xpcom/base/nsMemoryReporterManager.cpp
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -1641,32 +1641,50 @@ nsMemoryReporterManager::UnregisterStron
 
   MOZ_ASSERT(!mWeakReporters->Contains(aReporter));
 
   if (mStrongReporters->Contains(aReporter)) {
     mStrongReporters->RemoveEntry(aReporter);
     return NS_OK;
   }
 
+  // We don't register new reporters when the block is in place, but we do
+  // unregister existing reporters. This is so we don't keep holding strong
+  // references that these reporters aren't expecting (which can keep them
+  // alive longer than intended).
+  if (mSavedStrongReporters && mSavedStrongReporters->Contains(aReporter)) {
+    mSavedStrongReporters->RemoveEntry(aReporter);
+    return NS_OK;
+  }
+
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsMemoryReporterManager::UnregisterWeakReporter(nsIMemoryReporter* aReporter)
 {
   // This method is thread-safe.
   mozilla::MutexAutoLock autoLock(mMutex);
 
   MOZ_ASSERT(!mStrongReporters->Contains(aReporter));
 
   if (mWeakReporters->Contains(aReporter)) {
     mWeakReporters->RemoveEntry(aReporter);
     return NS_OK;
   }
 
+  // We don't register new reporters when the block is in place, but we do
+  // unregister existing reporters. This is so we don't keep holding weak
+  // references that the old reporters aren't expecting (which can end up as
+  // dangling pointers that lead to use-after-frees).
+  if (mSavedWeakReporters && mSavedWeakReporters->Contains(aReporter)) {
+    mSavedWeakReporters->RemoveEntry(aReporter);
+    return NS_OK;
+  }
+
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsMemoryReporterManager::BlockRegistrationAndHideExistingReporters()
 {
   // This method is thread-safe.
   mozilla::MutexAutoLock autoLock(mMutex);