Bug 1003658 - Avoid to create reference cycle in BluetoothProfileController which would cause memory leak. r=echou, f=shuang
authorJamin Liu <jaliu@mozilla.com>
Wed, 07 May 2014 10:57:27 +0800
changeset 181950 8cf161cd53a3c21b7ac98f7fa7c1df48edc5b5f7
parent 181949 15fbe6ab73345b9b64b0b9ac185f63aeab804dd5
child 181951 4cf9613444383b6fe01f7adf54c956af5b5f0531
push id43178
push usercbook@mozilla.com
push dateWed, 07 May 2014 12:13:50 +0000
treeherdermozilla-inbound@36b2f696ff10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs1003658
milestone32.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 1003658 - Avoid to create reference cycle in BluetoothProfileController which would cause memory leak. r=echou, f=shuang
dom/bluetooth/BluetoothProfileController.cpp
dom/bluetooth/BluetoothProfileController.h
--- a/dom/bluetooth/BluetoothProfileController.cpp
+++ b/dom/bluetooth/BluetoothProfileController.cpp
@@ -64,17 +64,16 @@ BluetoothProfileController::BluetoothPro
 {
   MOZ_ASSERT(!aDeviceAddress.IsEmpty());
   MOZ_ASSERT(aRunnable);
   MOZ_ASSERT(aCallback);
 
   mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
   MOZ_ASSERT(mTimer);
 
-  mCheckProfileStatusCallback = new CheckProfileStatusCallback(this);
   mProfiles.Clear();
 
   /**
    * If the service uuid is not specified, either connect multiple profiles
    * based on Cod, or disconnect all connected profiles.
    */
   if (!aServiceUuid) {
     mTarget.cod = aCod;
@@ -220,18 +219,18 @@ BluetoothProfileController::StartSession
 
   if (mProfiles.Length() < 1) {
     BT_LOGR("No queued profile.");
     EndSession();
     return;
   }
 
   if (mTimer) {
-    mTimer->InitWithCallback(mCheckProfileStatusCallback, CONNECTION_TIMEOUT_MS,
-                             nsITimer::TYPE_ONE_SHOT);
+    mTimer->InitWithCallback(new CheckProfileStatusCallback(this),
+                             CONNECTION_TIMEOUT_MS, nsITimer::TYPE_ONE_SHOT);
   }
 
   BT_LOGR("%s", mConnect ? "connecting" : "disconnecting");
 
   Next();
 }
 
 void
--- a/dom/bluetooth/BluetoothProfileController.h
+++ b/dom/bluetooth/BluetoothProfileController.h
@@ -134,14 +134,13 @@ private:
 
   // Either CoD or BluetoothServiceClass is assigned.
   union {
     uint32_t cod;
     BluetoothServiceClass service;
   } mTarget;
 
   nsCOMPtr<nsITimer> mTimer;
-  nsCOMPtr<nsITimerCallback> mCheckProfileStatusCallback;
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif