Skip to content

Commit

Permalink
Fix crashes when BLE rendezvous disconnects unexpectedly (#4413)
Browse files Browse the repository at this point in the history
* Fix crashes when BLE rendezvous disconnects unexpectedly

In BLE::OnBleEndPointConnectionClosed, the endpoint is already closed.
We try to close it again in the Transport::BLE destructor, causing a
crash.  Clear the endpoint in OnBleEndPointConnectionClosed to avoid
this case.

In addition, the OnRendezvousError callback ends up calling
RendezvousCleanup, which destroys the transport. We therefore cannot
call OnRendezvousConnectionClosed  after OnRendezvousError; |this| was
already freed in OnRendezvousError and we just need to return.

* Restyled by clang-format

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Jan 26, 2021
1 parent e36553c commit 40b8055
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/transport/BLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,20 @@ void BLE::OnBleEndPointConnectionClosed(BLEEndPoint * endPoint, BLE_ERROR err)
BLE * ble = reinterpret_cast<BLE *>(endPoint->mAppState);
ble->mState = State::kNotReady;

// Already closed, avoid closing again in our destructor.
ble->mBleEndPoint = nullptr;

if (ble->mDelegate)
{
if (err != BLE_NO_ERROR)
{
ble->mDelegate->OnRendezvousError(err);
}

ble->mDelegate->OnRendezvousConnectionClosed();
else
{
// OnRendezvousError may delete |ble|; don't call both callbacks.
ble->mDelegate->OnRendezvousConnectionClosed();
}
}
}

Expand Down

0 comments on commit 40b8055

Please sign in to comment.