Bug 1003658 - Avoid to create reference cycle in BluetoothProfileController which would cause memory leak. r=echou, f=shuang, a=1.4+
authorJamin Liu <jaliu@mozilla.com>
Wed, 07 May 2014 10:57:27 +0800
changeset 187377 60145dd8edb75edaff8f6d6510d985c26231c633
parent 187376 94888eb83c1db441ab875e151449fcd0014c3558
child 187384 d2169ca277a67db700b55598c838babaf9c067cf
push id62
push userryanvm@gmail.com
push dateWed, 07 May 2014 16:46:36 +0000
treeherdermozilla-b2g30_v1_4@60145dd8edb7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou, 1
bugs1003658
milestone30.0
Bug 1003658 - Avoid to create reference cycle in BluetoothProfileController which would cause memory leak. r=echou, f=shuang, a=1.4+
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
@@ -133,14 +133,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