@@ -389,6 +389,8 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle
389
389
mtr_weakify (self);
390
390
_systemTimeChangeObserverToken = [[NSNotificationCenter defaultCenter ] addObserverForName: NSSystemClockDidChangeNotification object: nil queue: nil usingBlock: ^(NSNotification * _Nonnull notification) {
391
391
mtr_strongify (self);
392
+ VerifyOrReturn (self);
393
+
392
394
std::lock_guard lock (self->_lock );
393
395
[self _resetStorageBehaviorState ];
394
396
}];
@@ -760,6 +762,8 @@ - (void)_ensureSubscriptionForExistingDelegates:(NSString *)reason
760
762
mtr_weakify (self);
761
763
[self _scheduleSubscriptionPoolWork: ^{
762
764
mtr_strongify (self);
765
+ VerifyOrReturn (self);
766
+
763
767
[self ->_deviceController asyncDispatchToMatterQueue: ^{
764
768
std::lock_guard lock (self->_lock );
765
769
[self _setupSubscriptionWithReason: [NSString stringWithFormat: @" %@ and scheduled subscription is happening" , reason]];
@@ -1168,16 +1172,16 @@ - (void)_scheduleSubscriptionPoolWork:(dispatch_block_t)workBlock inNanoseconds:
1168
1172
mtr_weakify (self);
1169
1173
dispatch_block_t workBlockToQueue = ^{
1170
1174
mtr_strongify (self);
1171
- if (nil == self) {
1172
- // This block may be delayed by a specified number of nanoseconds, potentially running after the device is deallocated.
1173
- // If so, MTRAsyncWorkItem::initWithQueue will assert on a nil queue, which will cause a crash.
1174
- return ;
1175
- }
1175
+ // This block may be delayed by a specified number of nanoseconds, potentially running after the device is deallocated.
1176
+ // If so, MTRAsyncWorkItem::initWithQueue will assert on a nil queue, which will cause a crash.
1177
+ VerifyOrReturn (self);
1176
1178
1177
1179
// In the case where a resubscription triggering event happened and already established, running the work block should result in a no-op
1178
1180
MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc ] initWithQueue: self .queue];
1179
1181
[workItem setReadyHandler: ^(id _Nonnull context, NSInteger retryCount, MTRAsyncWorkCompletionBlock _Nonnull completion) {
1180
1182
mtr_strongify (self);
1183
+ VerifyOrReturn (self);
1184
+
1181
1185
MTR_LOG (" %@ - work item is ready to attempt pooled subscription" , self);
1182
1186
os_unfair_lock_lock (&self->_lock );
1183
1187
#ifdef DEBUG
@@ -1257,6 +1261,8 @@ - (void)_handleResubscriptionNeededWithDelayOnDeviceQueue:(NSNumber *)resubscrip
1257
1261
mtr_weakify (self);
1258
1262
auto resubscriptionBlock = ^{
1259
1263
mtr_strongify (self);
1264
+ VerifyOrReturn (self);
1265
+
1260
1266
[self ->_deviceController asyncDispatchToMatterQueue: ^{
1261
1267
[self _triggerResubscribeWithReason: @" ResubscriptionNeeded timer fired" nodeLikelyReachable: NO ];
1262
1268
} errorHandler: ^(NSError * _Nonnull error) {
@@ -1369,6 +1375,8 @@ - (void)_doHandleSubscriptionReset:(NSNumber * _Nullable)retryDelay
1369
1375
mtr_weakify (self);
1370
1376
auto resubscriptionBlock = ^{
1371
1377
mtr_strongify (self);
1378
+ VerifyOrReturn (self);
1379
+
1372
1380
[self ->_deviceController asyncDispatchToMatterQueue: ^{
1373
1381
std::lock_guard lock (self->_lock );
1374
1382
[self _reattemptSubscriptionNowIfNeededWithReason: @" got subscription reset" ];
@@ -2386,9 +2394,9 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
2386
2394
mtr_weakify (self);
2387
2395
dispatch_after (dispatch_time (DISPATCH_TIME_NOW, static_cast <int64_t >(kSecondsToWaitBeforeMarkingUnreachableAfterSettingUpSubscription ) * static_cast <int64_t >(NSEC_PER_SEC)), self.queue , ^{
2388
2396
mtr_strongify (self);
2389
- if (self != nil ) {
2390
- [ self _markDeviceAsUnreachableIfNeverSubscribed ];
2391
- }
2397
+ VerifyOrReturn (self);
2398
+
2399
+ [ self _markDeviceAsUnreachableIfNeverSubscribed ];
2392
2400
});
2393
2401
}
2394
2402
@@ -3242,6 +3250,8 @@ - (void)_checkExpiredExpectedValues
3242
3250
mtr_weakify (self);
3243
3251
dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t ) (waitTime * NSEC_PER_SEC)), self.queue , ^{
3244
3252
mtr_strongify (self);
3253
+ VerifyOrReturn (self);
3254
+
3245
3255
[self _performScheduledExpirationCheck ];
3246
3256
});
3247
3257
}
0 commit comments