Bug 985949: Fix pointer handling in BlueZ backend, r=echou
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 24 Mar 2014 10:44:28 +0100
changeset 175023 3b1e6a7980d55d15698627a9bed9674e1611c544
parent 175022 6d66925d1b81a9fe547d07ba963d49c7a0f69ed6
child 175024 7a9c4ebb1ec6c5ae78088fba9a47f09a2c7c0d31
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersechou
bugs985949, 967364
milestone31.0a1
Bug 985949: Fix pointer handling in BlueZ backend, r=echou This is caused by bug 967364. We need to hand over data structures to DBus operations and forget about them if the operation returned success. Until now, we could just tell their nsRefPtrs to |forget| about them, but with bug 967364 applied we need to swap an empty value into the pointer.
dom/bluetooth/bluez/BluetoothDBusService.cpp
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp
@@ -41,16 +41,17 @@
 #include "mozilla/Hal.h"
 #include "mozilla/ipc/UnixSocket.h"
 #include "mozilla/ipc/DBusUtils.h"
 #include "mozilla/ipc/RawDBusConnection.h"
 #include "mozilla/LazyIdleThread.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/NullPtr.h"
 #include "mozilla/StaticMutex.h"
+#include "mozilla/unused.h"
 
 #if defined(MOZ_WIDGET_GONK)
 #include "cutils/properties.h"
 #include <dlfcn.h>
 #endif
 
 /**
  * Some rules for dealing with memory in DBus:
@@ -1111,17 +1112,17 @@ AppendDeviceName(BluetoothSignal& aSigna
 
   bool success = sDBusConnection->SendWithReply(
     AppendDeviceNameReplyHandler::Callback, handler.get(), 1000,
     NS_ConvertUTF16toUTF8(devicePath).get(), DBUS_DEVICE_IFACE,
     "GetProperties", DBUS_TYPE_INVALID);
 
   NS_ENSURE_TRUE_VOID(success);
 
-  handler.forget();
+  unused << handler.forget(); // picked up by callback handler
 }
 
 static DBusHandlerResult
 AgentEventFilter(DBusConnection *conn, DBusMessage *msg, void *data)
 {
   if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_METHOD_CALL) {
     BT_WARNING("%s: agent handler not interested (not a method call).\n",
                __FUNCTION__);
@@ -1456,17 +1457,17 @@ private:
       NS_ConvertUTF16toUTF8(sAdapterPath).get(),
       DBUS_ADAPTER_IFACE, "RegisterAgent",
       DBUS_TYPE_OBJECT_PATH, &agentPath,
       DBUS_TYPE_STRING, &capabilities,
       DBUS_TYPE_INVALID);
 
     NS_ENSURE_TRUE(success, false);
 
-    handler.forget();
+    unused << handler.forget(); // picked up by callback handler
 
     return true;
   }
 };
 
 class AddReservedServiceRecordsTask : public Task
 {
 public:
@@ -1500,17 +1501,17 @@ public:
       DBusReplyHandler::Callback, handler.get(), -1,
       mAdapterPath.get(),
       DBUS_ADAPTER_IFACE, "AddReservedServiceRecords",
       DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32,
       &services, ArrayLength(sServices), DBUS_TYPE_INVALID);
 
     NS_ENSURE_TRUE_VOID(success);
 
-    handler.forget();
+    unused << handler.forget(); /* picked up by callback handler */
   }
 
 private:
   const nsCString mAdapterPath;
 };
 
 class PrepareAdapterRunnable : public nsRunnable
 {
@@ -2186,17 +2187,17 @@ protected:
       NS_ConvertUTF16toUTF8(mAdapterPath).get(),
       DBUS_ADAPTER_IFACE, "GetProperties", DBUS_TYPE_INVALID);
 
     if (!success) {
       aReplyError = NS_LITERAL_STRING("SendWithReply failed");
       return false;
     }
 
-    handler.forget();
+    unused << handler.forget(); // picked up by callback handler
 
     return true;
   }
 
   bool HandleGetPropertiesReply(DBusMessage* aReply,
                                 nsAutoString& aReplyError)
   {
     BluetoothValue value;
@@ -2246,17 +2247,17 @@ public:
 
     bool success = sDBusConnection->SendWithReply(
       DefaultAdapterPathReplyHandler::Callback,
       handler.get(), 1000,
       "/", DBUS_MANAGER_IFACE, "DefaultAdapter",
       DBUS_TYPE_INVALID);
     NS_ENSURE_TRUE_VOID(success);
 
-    handler.forget();
+    unused << handler.forget(); // picked up by callback handler
   }
 
 private:
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
 nsresult
 BluetoothDBusService::GetDefaultAdapterPathInternal(
@@ -2316,17 +2317,17 @@ public:
     bool success = sDBusConnection->SendWithReply(
       OnSendDiscoveryMessageReply,
       static_cast<void*>(mRunnable.get()), -1,
       mAdapterPath.get(),
       DBUS_ADAPTER_IFACE, mMessageName.get(),
       DBUS_TYPE_INVALID);
     NS_ENSURE_TRUE_VOID(success);
 
-    mRunnable.forget();
+    unused << mRunnable.forget(); // picked up by callback handler
   }
 
 private:
   const nsCString mAdapterPath;
   const nsCString mMessageName;
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
@@ -2591,17 +2592,17 @@ protected:
       BluetoothArrayOfDevicePropertiesReplyHandler::Callback,
       handler.get(), 1000,
       NS_ConvertUTF16toUTF8(mObjectPath).get(),
       DBUS_DEVICE_IFACE, "GetProperties",
       DBUS_TYPE_INVALID);
 
     NS_ENSURE_TRUE(success, false);
 
-    handler.forget();
+    unused << handler.forget(); // picked up by callback handler
 
     return true;
   }
 
 private:
   nsString mAdapterPath;
   nsString mObjectPath;
   const nsTArray<nsString> mDeviceAddresses;
@@ -2752,17 +2753,17 @@ public:
 
     // msg is unref'd as part of SendWithReply
     bool success = sDBusConnection->SendWithReply(
       GetVoidCallback,
       static_cast<void*>(mRunnable),
       1000, msg);
     NS_ENSURE_TRUE_VOID(success);
 
-    mRunnable.forget();
+    unused << mRunnable.forget(); // picked up by callback handler
   }
 
 private:
   const nsCString mAdapterPath;
   BluetoothObjectType mType;
   const nsCString mName;
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
 };
@@ -2907,17 +2908,17 @@ public:
       DBUS_ADAPTER_IFACE,
       "CreatePairedDevice",
       DBUS_TYPE_STRING, &deviceAddress,
       DBUS_TYPE_OBJECT_PATH, &deviceAgentPath,
       DBUS_TYPE_STRING, &capabilities,
       DBUS_TYPE_INVALID);
     NS_ENSURE_TRUE_VOID(success);
 
-    mRunnable.forget();
+    unused << mRunnable.forget(); // picked up by callback handler
 
     /**
      * FIXME: Bug 820274
      *
      * If the user turns off Bluetooth in the middle of pairing process,
      * the callback function GetObjectPathCallback may still be called
      * while enabling next time by dbus daemon. To prevent this from
      * happening, added a flag to distinguish if Bluetooth has been
@@ -2979,17 +2980,17 @@ public:
     bool success = sDBusConnection->SendWithReply(
       OnRemoveDeviceReply, static_cast<void*>(mRunnable.get()), -1,
       NS_ConvertUTF16toUTF8(mAdapterPath).get(),
       DBUS_ADAPTER_IFACE, "RemoveDevice",
       DBUS_TYPE_OBJECT_PATH, &cstrDeviceObjectPath,
       DBUS_TYPE_INVALID);
     NS_ENSURE_TRUE_VOID(success);
 
-    mRunnable.forget();
+    unused << mRunnable.forget(); // picked up by callback handler
   }
 
 protected:
   static void OnRemoveDeviceReply(DBusMessage* aReply, void* aData)
   {
     nsAutoString errorStr;
 
     if (!aReply) {
@@ -3506,17 +3507,17 @@ public:
       OnGetServiceChannelReplyHandler::Callback, handler, -1,
       NS_ConvertUTF16toUTF8(objectPath).get(),
       DBUS_DEVICE_IFACE, "GetServiceAttributeValue",
       DBUS_TYPE_STRING, &cstrServiceUUID,
       DBUS_TYPE_UINT16, &sProtocolDescriptorList,
       DBUS_TYPE_INVALID);
     NS_ENSURE_TRUE_VOID(success);
 
-    handler.forget();
+    unused << handler.forget(); // picked up by callback handler
   }
 
 private:
   nsString mAdapterPath;
   nsString mDeviceAddress;
   nsString mServiceUUID;
   BluetoothProfileManagerBase* mBluetoothProfileManager;
 };
@@ -3808,17 +3809,17 @@ public:
       DBUS_TYPE_STRING, &album,
       DBUS_TYPE_STRING, &mediaNumber,
       DBUS_TYPE_STRING, &totalMediaCount,
       DBUS_TYPE_STRING, &duration,
       DBUS_TYPE_STRING, &genre,
       DBUS_TYPE_INVALID);
     NS_ENSURE_TRUE_VOID(success);
 
-    mRunnable.forget();
+    unused << mRunnable.forget(); // picked up by callback handler
   }
 
 private:
   const nsCString mObjectPath;
   const nsCString mTitle;
   const nsCString mArtist;
   const nsCString mAlbum;
   int64_t mMediaNumber;
@@ -3936,17 +3937,17 @@ public:
       mObjectPath.get(),
       DBUS_CTL_IFACE, "UpdatePlayStatus",
       DBUS_TYPE_UINT32, &mDuration,
       DBUS_TYPE_UINT32, &mPosition,
       DBUS_TYPE_UINT32, &tempPlayStatus,
       DBUS_TYPE_INVALID);
     NS_ENSURE_TRUE_VOID(success);
 
-    mRunnable.forget();
+    unused << mRunnable.forget(); // picked up by callback handler
   }
 
 private:
   const nsCString mObjectPath;
   int64_t mDuration;
   int64_t mPosition;
   ControlPlayStatus mPlayStatus;
   nsRefPtr<BluetoothReplyRunnable> mRunnable;