Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing lock around _controllers access. #28384

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ @interface MTRDeviceControllerFactory ()
//
// 1) The only mutating accesses to the controllers array happen when the
// current queue is not the Matter queue. This is a good assumption, because
// the implementation of the fucntions that mutate the array do sync dispatch
// the implementation of the functions that mutate the array do sync dispatch
// to the Matter queue, which would deadlock if they were called when that
// queue was the current queue.
// 2) It's our API consumer's responsibility to serialize access to us from
Expand Down Expand Up @@ -597,7 +597,11 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo
return;
}

for (MTRDeviceController * existing in _controllers) {
os_unfair_lock_lock(&_controllersLock);
NSArray<MTRDeviceController *> * controllersCopy = [_controllers copy];
os_unfair_lock_unlock(&_controllersLock);

for (MTRDeviceController * existing in controllersCopy) {
BOOL isRunning = YES; // assume the worst
if ([existing isRunningOnFabric:fabricTable fabricIndex:fabric->GetFabricIndex() isRunning:&isRunning]
!= CHIP_NO_ERROR) {
Expand Down