Bug 1138770 - Make memory reporters that have been stashed for testing eligible for unregistration. r=mccr8, a=lsblakk
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 02 Mar 2015 18:55:42 -0800
changeset 247986 7a9812f7da3ff5e369e3cdfe024176297f21a938
parent 247985 a76195f874dedc6d57c5b7fcae3f235634447ebf
child 247987 441dc7e176513499e9dd7e9305a1cf082fd432a5
push id7733
push userryanvm@gmail.com
push dateWed, 11 Mar 2015 20:56:10 +0000
treeherdermozilla-aurora@78a8634d4ee9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8, lsblakk
bugs1138770
milestone38.0a2
Bug 1138770 - Make memory reporters that have been stashed for testing eligible for unregistration. r=mccr8, a=lsblakk
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);