Bug 1264887: |nsWifiScannerDBus|: Hold DBusConnection reference in |RefPtr|, r=josh
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 19 Apr 2016 16:26:01 +0200
changeset 331767 e07c615c423b808aa018431dc8ed221e39506552
parent 331766 4a0e32f4856906445492002e444085f52803f25a
child 331768 59a13ac2a4d086193ae997f68d7f5270b20dd6af
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh
bugs1264887
milestone48.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 1264887: |nsWifiScannerDBus|: Hold DBusConnection reference in |RefPtr|, r=josh
netwerk/wifi/nsWifiScannerDBus.cpp
netwerk/wifi/nsWifiScannerDBus.h
--- a/netwerk/wifi/nsWifiScannerDBus.cpp
+++ b/netwerk/wifi/nsWifiScannerDBus.cpp
@@ -7,28 +7,26 @@
 
 namespace mozilla {
 
 nsWifiScannerDBus::nsWifiScannerDBus(nsCOMArray<nsWifiAccessPoint> *aAccessPoints)
 : mAccessPoints(aAccessPoints)
 {
   MOZ_ASSERT(mAccessPoints);
 
-  mConnection = dbus_bus_get(DBUS_BUS_SYSTEM, nullptr);
+  mConnection =
+    already_AddRefed<DBusConnection>(dbus_bus_get(DBUS_BUS_SYSTEM, nullptr));
   MOZ_ASSERT(mConnection);
   dbus_connection_set_exit_on_disconnect(mConnection, false);
 
   MOZ_COUNT_CTOR(nsWifiScannerDBus);
 }
 
 nsWifiScannerDBus::~nsWifiScannerDBus()
 {
-  if (!mConnection) {
-    dbus_connection_unref(mConnection);
-  }
   MOZ_COUNT_DTOR(nsWifiScannerDBus);
 }
 
 nsresult
 nsWifiScannerDBus::Scan()
 {
   return SendMessage("org.freedesktop.NetworkManager",
                      "/org/freedesktop/NetworkManager",
--- a/netwerk/wifi/nsWifiScannerDBus.h
+++ b/netwerk/wifi/nsWifiScannerDBus.h
@@ -5,16 +5,18 @@
 #ifndef NSWIFIAPSCANNERDBUS_H_
 #define NSWIFIAPSCANNERDBUS_H_
 
 #include "nsCOMArray.h"
 
 #define DBUS_API_SUBJECT_TO_CHANGE
 #include <dbus/dbus.h>
 
+#include "mozilla/ipc/DBusConnectionRefPtr.h"
+
 class nsWifiAccessPoint;
 
 namespace mozilla {
 
 class nsWifiScannerDBus final
 {
 public:
   explicit nsWifiScannerDBus(nsCOMArray<nsWifiAccessPoint>* aAccessPoints);
@@ -29,15 +31,15 @@ private:
   nsresult IdentifyDevices(DBusMessage* aMsg);
   nsresult IdentifyDeviceType(DBusMessage* aMsg, const char* aDevicePath);
   nsresult IdentifyAccessPoints(DBusMessage* aMsg);
   nsresult IdentifyAPProperties(DBusMessage* aMsg);
   nsresult StoreSsid(DBusMessageIter* aVariant, nsWifiAccessPoint* aAp);
   nsresult SetMac(DBusMessageIter* aVariant, nsWifiAccessPoint* aAp);
   nsresult GetDBusIterator(DBusMessage* aMsg, DBusMessageIter* aIterArray);
 
-  DBusConnection* mConnection;
+  RefPtr<DBusConnection> mConnection;
   nsCOMArray<nsWifiAccessPoint>* mAccessPoints;
 };
 
 } // mozilla
 
 #endif // NSWIFIAPSCANNERDBUS_H_