Bug 982072 - Don't leak the argument passed to RegisterStrongMemoryReporter if we fail to get the service; r=froydnj

This commit is contained in:
Ehsan Akhgari 2014-03-11 14:15:27 -04:00
Родитель 0d3ad74d44
Коммит 8d63d692dd
1 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@ -1741,12 +1741,16 @@ namespace mozilla {
nsresult nsresult
RegisterStrongMemoryReporter(nsIMemoryReporter* aReporter) 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 = nsCOMPtr<nsIMemoryReporterManager> mgr =
do_GetService("@mozilla.org/memory-reporter-manager;1"); do_GetService("@mozilla.org/memory-reporter-manager;1");
if (!mgr) { if (!mgr) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mgr->RegisterStrongReporter(aReporter); return mgr->RegisterStrongReporter(reporter);
} }
nsresult nsresult