From 7e1e6e5ff95363def59391b0bdbf3e8d50bc9295 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 11 Mar 2014 14:15:27 -0400 Subject: [PATCH] Bug 982072 - Don't leak the argument passed to RegisterStrongMemoryReporter if we fail to get the service; r=froydnj --- xpcom/base/nsMemoryReporterManager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index 0ce5a4c3cba..d65b782c508 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -1741,12 +1741,16 @@ 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 reporter = aReporter; + nsCOMPtr mgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); if (!mgr) { return NS_ERROR_FAILURE; } - return mgr->RegisterStrongReporter(aReporter); + return mgr->RegisterStrongReporter(reporter); } nsresult