Bug 1047757: Call ClearOnShutdown(sBluetoothService) to fix memory leak. r=shuang

This commit is contained in:
Jocelyn Liu 2014-08-07 14:01:24 +08:00
Родитель f984628edc
Коммит 763f8f19a9
2 изменённых файлов: 12 добавлений и 10 удалений

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

@ -20,6 +20,7 @@
#include "BluetoothUtils.h"
#include "jsapi.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/unused.h"
@ -732,15 +733,15 @@ BluetoothService::Get()
}
// Create new instance, register, return
nsRefPtr<BluetoothService> service = BluetoothService::Create();
NS_ENSURE_TRUE(service, nullptr);
sBluetoothService = BluetoothService::Create();
NS_ENSURE_TRUE(sBluetoothService, nullptr);
if (!service->Init()) {
service->Cleanup();
if (!sBluetoothService->Init()) {
sBluetoothService->Cleanup();
return nullptr;
}
sBluetoothService = service;
ClearOnShutdown(&sBluetoothService);
return sBluetoothService;
}

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

@ -20,6 +20,7 @@
#include "BluetoothUtils.h"
#include "jsapi.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/unused.h"
@ -663,15 +664,15 @@ BluetoothService::Get()
}
// Create new instance, register, return
nsRefPtr<BluetoothService> service = BluetoothService::Create();
NS_ENSURE_TRUE(service, nullptr);
sBluetoothService = BluetoothService::Create();
NS_ENSURE_TRUE(sBluetoothService, nullptr);
if (!service->Init()) {
service->Cleanup();
if (!sBluetoothService->Init()) {
sBluetoothService->Cleanup();
return nullptr;
}
sBluetoothService = service;
ClearOnShutdown(&sBluetoothService);
return sBluetoothService;
}