Bug 784728: Make Gonk's battery observer a RefPtr, fixing an abort on process exit in debug builds. r=jlebar
authorMarshall Culpepper <marshall@mozilla.com>
Wed, 29 Aug 2012 12:32:56 -0300
changeset 105822 c05251c5a7e3e96d7cd507e27db09f802a1f8a53
parent 105821 3925750b682fb35b7bd639c6a1b031adda991ecf
child 105823 b739aa9d9ede6bd90794eabdacdb46fca8a011fd
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersjlebar
bugs784728
milestone18.0a1
Bug 784728: Make Gonk's battery observer a RefPtr, fixing an abort on process exit in debug builds. r=jlebar
hal/gonk/GonkHal.cpp
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -35,16 +35,17 @@
 #include "base/message_loop.h"
 
 #include "Hal.h"
 #include "HalImpl.h"
 #include "mozilla/dom/battery/Constants.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/Services.h"
+#include "mozilla/StaticPtr.h"
 #include "mozilla/Preferences.h"
 #include "nsAlgorithm.h"
 #include "nsPrintfCString.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsIRunnable.h"
 #include "nsScreenManagerGonk.h"
 #include "nsThreadUtils.h"
@@ -245,17 +246,17 @@ public:
   }
 
 private:
   nsRefPtr<BatteryUpdater> mUpdater;
 };
 
 // sBatteryObserver is owned by the IO thread. Only the IO thread may
 // create or destroy it.
-static BatteryObserver *sBatteryObserver = NULL;
+static StaticRefPtr<BatteryObserver> sBatteryObserver;
 
 static void
 RegisterBatteryObserverIOThread()
 {
   MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
   MOZ_ASSERT(!sBatteryObserver);
 
   sBatteryObserver = new BatteryObserver();
@@ -272,17 +273,16 @@ EnableBatteryNotifications()
 
 static void
 UnregisterBatteryObserverIOThread()
 {
   MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
   MOZ_ASSERT(sBatteryObserver);
 
   UnregisterUeventListener(sBatteryObserver);
-  delete sBatteryObserver;
   sBatteryObserver = NULL;
 }
 
 void
 DisableBatteryNotifications()
 {
   XRE_GetIOMessageLoop()->PostTask(
       FROM_HERE,