Skip to content

Commit

Permalink
Add missing locks around nodeIDToDeviceMap access. (project-chip#28675)
Browse files Browse the repository at this point in the history
Those accesses are all supposed to happen while holding _deviceMapLock, but we
had some that were not locking.
  • Loading branch information
bzbarsky-apple authored Aug 12, 2023
1 parent 1309e7d commit b0b0d58
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,17 @@ - (void)cleanupAfterStartup
{
// Invalidate our MTRDevice instances before we shut down our secure
// sessions and whatnot, so they don't start trying to resubscribe when we
// do the secure session shutdowns.
for (MTRDevice * device in [self.nodeIDToDeviceMap allValues]) {
// do the secure session shutdowns. Since we don't want to hold the lock
// while calling out into arbitrary invalidation code, snapshot the list of
// devices before we start invalidating.
os_unfair_lock_lock(&_deviceMapLock);
NSArray<MTRDevice *> * devices = [self.nodeIDToDeviceMap allValues];
[self.nodeIDToDeviceMap removeAllObjects];
os_unfair_lock_unlock(&_deviceMapLock);

for (MTRDevice * device in devices) {
[device invalidate];
}
[self.nodeIDToDeviceMap removeAllObjects];
[self stopBrowseForCommissionables];

[_factory controllerShuttingDown:self];
Expand Down

0 comments on commit b0b0d58

Please sign in to comment.