Skip to content

Commit 1bd8e40

Browse files
authored
[Darwin] MTRDevice _delegateExists cannot be called without holding lock (project-chip#37662)
1 parent 38cc24b commit 1bd8e40

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+6
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ - (void)invalidate
253253
[self _cancelAllAttributeValueWaiters];
254254
}
255255

256+
- (BOOL)delegateExists
257+
{
258+
std::lock_guard lock(_lock);
259+
return [self _delegateExists];
260+
}
261+
256262
- (BOOL)_delegateExists
257263
{
258264
os_unfair_lock_assert_owner(&self->_lock);

src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (void)_updateRegistrationInfo
7979

8080
for (NSNumber * nodeID in [self.nodeIDToDeviceMap keyEnumerator]) {
8181
MTRDevice * device = [self _deviceForNodeID:nodeID createIfNeeded:NO];
82-
if ([device _delegateExists]) {
82+
if ([device delegateExists]) {
8383
NSMutableDictionary * nodeDictionary = [NSMutableDictionary dictionary];
8484
MTR_REQUIRED_ATTRIBUTE(MTRDeviceControllerRegistrationNodeIDKey, nodeID, nodeDictionary)
8585

src/darwin/Framework/CHIP/MTRDevice_Internal.h

+4
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ MTR_DIRECT_MEMBERS
146146
// Returns YES if any non-null delegates were found
147147
- (BOOL)_iterateDelegatesWithBlock:(void(NS_NOESCAPE ^ _Nullable)(MTRDeviceDelegateInfo * delegateInfo))block;
148148

149+
// For subclasses to call while holding lock
149150
- (BOOL)_delegateExists;
150151

152+
// For device controller or other objects to call
153+
- (BOOL)delegateExists;
154+
151155
// Must be called by subclasses or MTRDevice implementation only.
152156
- (void)_delegateAdded:(id<MTRDeviceDelegate>)delegate;
153157
- (void)_delegateRemoved:(id<MTRDeviceDelegate>)delegate;

0 commit comments

Comments
 (0)