Bug 1264887: |nsWifiScannerDBus|: Hold DBusMessage references in |RefPtr|, r=josh
☠☠ backed out by 764146352ed7 ☠ ☠
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 19 Apr 2016 11:09:02 +0200
changeset 331707 348413c98656addb864011b0dd3914f3710f4f06
parent 331706 3e0859b436d6c3e5b70afc599b814564d600415b
child 331708 0220fd37d605291b2db7061e86d47252ed28aa7a
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 DBusMessage references in |RefPtr|, r=josh
netwerk/wifi/nsWifiScannerDBus.cpp
--- a/netwerk/wifi/nsWifiScannerDBus.cpp
+++ b/netwerk/wifi/nsWifiScannerDBus.cpp
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsWifiScannerDBus.h"
+#include "mozilla/ipc/DBusMessageRefPtr.h"
 #include "nsWifiAccessPoint.h"
 
 namespace mozilla {
 
 nsWifiScannerDBus::nsWifiScannerDBus(nsCOMArray<nsWifiAccessPoint> *aAccessPoints)
 : mAccessPoints(aAccessPoints)
 {
   MOZ_ASSERT(mAccessPoints);
@@ -33,19 +34,19 @@ nsWifiScannerDBus::Scan()
                      "GetDevices");
 }
 
 nsresult
 nsWifiScannerDBus::SendMessage(const char* aInterface,
                                const char* aPath,
                                const char* aFuncCall)
 {
-  DBusMessage* msg =
+  RefPtr<DBusMessage> msg = already_AddRefed<DBusMessage>(
     dbus_message_new_method_call("org.freedesktop.NetworkManager",
-                                 aPath, aInterface, aFuncCall);
+                                 aPath, aInterface, aFuncCall));
   if (!msg) {
     return NS_ERROR_FAILURE;
   }
 
   DBusMessageIter argsIter;
   dbus_message_iter_init_append(msg, &argsIter);
 
   if (!strcmp(aFuncCall, "Get")) {
@@ -68,19 +69,19 @@ nsWifiScannerDBus::SendMessage(const cha
   }
 
   DBusError err;
   dbus_error_init(&err);
 
   // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html
   // Refer to function dbus_connection_send_with_reply_and_block.
   const uint32_t DBUS_DEFAULT_TIMEOUT = -1;
-  DBusMessage* reply = nullptr;
-  reply = dbus_connection_send_with_reply_and_block(mConnection, msg,
-                                                    DBUS_DEFAULT_TIMEOUT, &err);
+  RefPtr<DBusMessage> reply = already_AddRefed<DBusMessage>(
+    dbus_connection_send_with_reply_and_block(mConnection, msg,
+                                              DBUS_DEFAULT_TIMEOUT, &err));
   if (dbus_error_is_set(&err)) {
     dbus_error_free(&err);
 
     // In the GetAccessPoints case, if there are no access points, error is set.
     // We don't want to error out here.
     if (!strcmp(aFuncCall, "GetAccessPoints")) {
       return NS_OK;
     }
@@ -94,17 +95,16 @@ nsWifiScannerDBus::SendMessage(const cha
     rv = IdentifyDeviceType(reply, aPath);
   } else if (!strcmp(aFuncCall, "GetAccessPoints")) {
     rv = IdentifyAccessPoints(reply);
   } else if (!strcmp(aFuncCall, "GetAll")) {
     rv = IdentifyAPProperties(reply);
   } else {
     rv = NS_ERROR_FAILURE;
   }
-  dbus_message_unref(reply);
   return rv;
 }
 
 nsresult
 nsWifiScannerDBus::IdentifyDevices(DBusMessage* aMsg)
 {
   DBusMessageIter iter;
   nsresult rv = GetDBusIterator(aMsg, &iter);