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

[Darwin] MTRDevice work blocks should only weakly reference self #37757

Merged
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
11 changes: 10 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ - (void)_scheduleNextUpdate:(UInt64)nextUpdateInSeconds
{
mtr_weakify(self);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (nextUpdateInSeconds * NSEC_PER_SEC)), self.queue, ^{
MTR_LOG_DEBUG("%@ Timer expired, start Device Time Update", self);
mtr_strongify(self);
MTR_LOG_DEBUG("%@ Timer expired, start Device Time Update", self);
if (self) {
[self _performScheduledTimeUpdate];
} else {
Expand Down Expand Up @@ -3659,8 +3659,12 @@ - (void)invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)c
for (NSArray<MTRCommandWithRequiredResponse *> * commandGroup in [commands reverseObjectEnumerator]) {
// We want to invoke all the commands in the group in order, propagating along the list of
// current responses. Build up that linked list of command invokes via chaining the completions.
mtr_weakify(self);
for (MTRCommandWithRequiredResponse * command in [commandGroup reverseObjectEnumerator]) {
auto commandInvokeBlock = ^(BOOL allSucceededSoFar, NSArray<MTRDeviceResponseValueDictionary> * previousResponses) {
mtr_strongify(self);
VerifyOrReturn(self, MTR_LOG_DEBUG("invokeCommands commandInvokeBlock called back with nil MTRDevice"));

[self invokeCommandWithEndpointID:command.path.endpoint
clusterID:command.path.cluster
commandID:command.path.command
Expand All @@ -3669,6 +3673,8 @@ - (void)invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)c
expectedValueInterval:nil
queue:self.queue
completion:^(NSArray<NSDictionary<NSString *, id> *> * responses, NSError * error) {
mtr_strongify(self);
VerifyOrReturn(self, MTR_LOG_DEBUG("invokeCommands invokeCommandWithEndpointID completion called back with nil MTRDevice"));
if (error != nil) {
nextCompletion(NO, [previousResponses arrayByAddingObject:@ {
MTRCommandPathKey : command.path,
Expand Down Expand Up @@ -3701,6 +3707,9 @@ - (void)invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)c
}

auto commandGroupInvokeBlock = ^(BOOL allSucceededSoFar, NSArray<MTRDeviceResponseValueDictionary> * previousResponses) {
mtr_strongify(self);
VerifyOrReturn(self, MTR_LOG_DEBUG("invokeCommands commandGroupInvokeBlock called back with nil MTRDevice"));

if (allSucceededSoFar == NO) {
// Don't start a new command group if something failed in the
// previous one. Note that we might be running on self.queue here, so make sure we
Expand Down
Loading