diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-09-27 09:52:46 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-09-27 08:45:01 +0000 |
commit | b4e9cc6ab73019c04182248a8f65e9fa840d382b (patch) | |
tree | bc180e00bd9125681adc51848e5287e0d2c63c28 /src | |
parent | 7d7651fb3bd0c2bdeb6159202d30cf475611da58 (diff) |
winrt: Avoid crash on device discovery when device has to be paired
If a device has to be paired during device discovery on winrt it is
possible that the pairing dialog is shown, while discovery hits its
timeout. We have to protect against a late callback which tries to access
a deleted object.
Change-Id: I9756f993b4a31080b1ef518953bee6e75a24e315
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 309804a8..ef2a69b1 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -476,10 +476,14 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFound(ComPtr<IB // We need a paired device in order to be able to obtain its information if (!isPaired) { ComPtr<IAsyncOperation<DevicePairingResult *>> pairingOp; + QPointer<QWinRTBluetoothDeviceDiscoveryWorker> tPointer(this); hr = pairing.Get()->PairAsync(&pairingOp); Q_ASSERT_SUCCEEDED(hr); pairingOp.Get()->put_Completed( - Callback<IAsyncOperationCompletedHandler<DevicePairingResult *>>([device, this](IAsyncOperation<DevicePairingResult *> *op, AsyncStatus status) { + Callback<IAsyncOperationCompletedHandler<DevicePairingResult *>>([device, tPointer](IAsyncOperation<DevicePairingResult *> *op, AsyncStatus status) { + if (!tPointer) + return S_OK; + if (status != AsyncStatus::Completed) { qCDebug(QT_BT_WINRT) << "Could not pair device"; return S_OK; @@ -496,7 +500,7 @@ HRESULT QWinRTBluetoothDeviceDiscoveryWorker::onBluetoothLEDeviceFound(ComPtr<IB return S_OK; } - onBluetoothLEDeviceFound(device, OmitPairingCheck); + tPointer->onBluetoothLEDeviceFound(device, OmitPairingCheck); return S_OK; }).Get()); return S_OK; |