From 69782465dc2a2e14241f0252830a71ca79720ac7 Mon Sep 17 00:00:00 2001 From: Eric Chou Date: Tue, 12 Nov 2013 17:37:30 +0800 Subject: [PATCH] Bug 936711 - Fix crash which happened at disabling Bluetooth during reconnection, r=gyeh --- dom/bluetooth/BluetoothA2dpManager.cpp | 12 ++++++++++-- dom/bluetooth/BluetoothHidManager.cpp | 12 ++++++++++-- dom/bluetooth/linux/BluetoothDBusService.cpp | 13 +++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/dom/bluetooth/BluetoothA2dpManager.cpp b/dom/bluetooth/BluetoothA2dpManager.cpp index 2e4d25399441..bb28332f3279 100644 --- a/dom/bluetooth/BluetoothA2dpManager.cpp +++ b/dom/bluetooth/BluetoothA2dpManager.cpp @@ -166,7 +166,11 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress, mDeviceAddress = aDeviceAddress; mController = aController; - bs->SendSinkMessage(aDeviceAddress, NS_LITERAL_STRING("Connect")); + if (NS_FAILED(bs->SendSinkMessage(aDeviceAddress, + NS_LITERAL_STRING("Connect")))) { + aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); + return; + } } void @@ -192,7 +196,11 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController) mController = aController; - bs->SendSinkMessage(mDeviceAddress, NS_LITERAL_STRING("Disconnect")); + if (NS_FAILED(bs->SendSinkMessage(mDeviceAddress, + NS_LITERAL_STRING("Disconnect")))) { + aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); + return; + } } void diff --git a/dom/bluetooth/BluetoothHidManager.cpp b/dom/bluetooth/BluetoothHidManager.cpp index 8abada0e968e..378d958e96e7 100644 --- a/dom/bluetooth/BluetoothHidManager.cpp +++ b/dom/bluetooth/BluetoothHidManager.cpp @@ -125,7 +125,11 @@ BluetoothHidManager::Connect(const nsAString& aDeviceAddress, mDeviceAddress = aDeviceAddress; mController = aController; - bs->SendInputMessage(aDeviceAddress, NS_LITERAL_STRING("Connect")); + if (NS_FAILED(bs->SendInputMessage(aDeviceAddress, + NS_LITERAL_STRING("Connect")))) { + aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); + return; + } } void @@ -153,7 +157,11 @@ BluetoothHidManager::Disconnect(BluetoothProfileController* aController) mController = aController; - bs->SendInputMessage(mDeviceAddress, NS_LITERAL_STRING("Disconnect")); + if (NS_FAILED(bs->SendInputMessage(mDeviceAddress, + NS_LITERAL_STRING("Disconnect")))) { + aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); + return; + } } void diff --git a/dom/bluetooth/linux/BluetoothDBusService.cpp b/dom/bluetooth/linux/BluetoothDBusService.cpp index 2500164c2c8c..17abfcdb597a 100644 --- a/dom/bluetooth/linux/BluetoothDBusService.cpp +++ b/dom/bluetooth/linux/BluetoothDBusService.cpp @@ -2003,6 +2003,8 @@ BluetoothDBusService::SendAsyncDBusMessage(const nsAString& aObjectPath, MOZ_ASSERT(!aObjectPath.IsEmpty()); MOZ_ASSERT(aInterface); + NS_ENSURE_TRUE(mConnection, NS_ERROR_FAILURE); + nsAutoPtr serviceClass(new BluetoothServiceClass()); if (!strcmp(aInterface, DBUS_SINK_IFACE)) { *serviceClass = BluetoothServiceClass::A2DP; @@ -2587,12 +2589,15 @@ BluetoothDBusService::SetPairingConfirmationInternal( static void NextBluetoothProfileController() { - sControllerArray[0] = nullptr; + MOZ_ASSERT(NS_IsMainThread()); + + // First, remove the task at the front which has been already done. + NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty()); sControllerArray.RemoveElementAt(0); - if (!sControllerArray.IsEmpty()) { - sControllerArray[0]->Start(); - } + // Re-check if the task array is empty, if it's not, the next task will begin. + NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty()); + sControllerArray[0]->Start(); } static void