Skip to content

Commit 90b6caf

Browse files
vivien-appleyyzhong-g
authored andcommitted
[Matter.framework] MTRAsyncWorkItem::initWithQueue will assert when the delayed scheduleSubscriptionPool fires after the deallocation of the MTRDevice (project-chip#35987)
1 parent def51ad commit 90b6caf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+6
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,12 @@ - (void)_scheduleSubscriptionPoolWork:(dispatch_block_t)workBlock inNanoseconds:
11701170
mtr_weakify(self);
11711171
dispatch_block_t workBlockToQueue = ^{
11721172
mtr_strongify(self);
1173+
if (nil == self) {
1174+
// This block may be delayed by a specified number of nanoseconds, potentially running after the device is deallocated.
1175+
// If so, MTRAsyncWorkItem::initWithQueue will assert on a nil queue, which will cause a crash.
1176+
return;
1177+
}
1178+
11731179
// In the case where a resubscription triggering event happened and already established, running the work block should result in a no-op
11741180
MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc] initWithQueue:self.queue];
11751181
[workItem setReadyHandler:^(id _Nonnull context, NSInteger retryCount, MTRAsyncWorkCompletionBlock _Nonnull completion) {

0 commit comments

Comments
 (0)