Bug 982072 - Don't leak the argument passed to RegisterStrongMemoryReporter if we fail to get the service; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 11 Mar 2014 14:15:27 -0400
changeset 191284 ae7ee1ee97a34842cdba1e7d2e4109626b9c788d
parent 191283 596afdd963e73e31691268febd9d4e25ce0ce5e2
child 191285 7942f3fb5280abea3226ba812871f344e981b70f
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs982072
milestone30.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 982072 - Don't leak the argument passed to RegisterStrongMemoryReporter if we fail to get the service; r=froydnj
xpcom/base/nsMemoryReporterManager.cpp
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -1736,22 +1736,26 @@ nsMemoryReporterManager::SizeOfTab(nsIDO
   return NS_OK;
 }
 
 namespace mozilla {
 
 nsresult
 RegisterStrongMemoryReporter(nsIMemoryReporter* aReporter)
 {
+  // Hold a strong reference to the argument to make sure it gets released if
+  // we return early below.
+  nsCOMPtr<nsIMemoryReporter> reporter = aReporter;
+
   nsCOMPtr<nsIMemoryReporterManager> mgr =
     do_GetService("@mozilla.org/memory-reporter-manager;1");
   if (!mgr) {
     return NS_ERROR_FAILURE;
   }
-  return mgr->RegisterStrongReporter(aReporter);
+  return mgr->RegisterStrongReporter(reporter);
 }
 
 nsresult
 RegisterWeakMemoryReporter(nsIMemoryReporter* aReporter)
 {
   nsCOMPtr<nsIMemoryReporterManager> mgr =
     do_GetService("@mozilla.org/memory-reporter-manager;1");
   if (!mgr) {