Skip to content

Commit

Permalink
Fix #26115: Setup discriminator parameter corruption (#26116)
Browse files Browse the repository at this point in the history
* Fix #26115: Setup discriminator parameter corruption

The setup discriminator parameter is being passed by reference, but
by the time the block is run by dispatch, that reference points to
stack contents that have been changed.  Making a local copy of the
discriminator fixes the problem.

* Add comment explaining why we are copying the incoming discriminator.

---------

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Oct 12, 2023
1 parent 10e0e0a commit 15d306e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ - (BOOL)isConnecting;
dispatch_queue_t bleWorkQueue;

void BleConnectionDelegateImpl::NewConnection(
Ble::BleLayer * bleLayer, void * appState, const SetupDiscriminator & deviceDiscriminator)
Ble::BleLayer * bleLayer, void * appState, const SetupDiscriminator & inDeviceDiscriminator)
{
assertChipStackLockedByCurrentThread();

// Make a copy of the device discriminator for the block to capture.
SetupDiscriminator deviceDiscriminator = inDeviceDiscriminator;

ChipLogProgress(Ble, "%s", __FUNCTION__);
if (!bleWorkQueue) {
bleWorkQueue = dispatch_queue_create(kBleWorkQueueName, DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
Expand Down

0 comments on commit 15d306e

Please sign in to comment.