Skip to content

Commit

Permalink
Issue #22935 [Darwin] MTRBaseSubscriptionCallback OnDone callback bei…
Browse files Browse the repository at this point in the history
…ng called async can lead to crashes (#22978)
  • Loading branch information
jtung-apple authored and pull[bot] committed Jul 20, 2023
1 parent d751aad commit 2164354
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,21 @@
mOnDoneHandler = nil;
dispatch_async(mQueue, ^{
callback(err);
if (onDoneHandler) {
onDoneHandler();
}
});

if (aCancelSubscription) {
if (onDoneHandler) {
// To guarantee the async onDoneHandler call is made before
// deletion, so that clean up can happen while the callback
// object is still alive (and therefore cluster cache), queue
// deletion after calling the onDoneHandler
mHaveQueuedDeletion = true;
dispatch_async(mQueue, ^{
onDoneHandler();
dispatch_async(DeviceLayer::PlatformMgrImpl().GetWorkQueue(), ^{
delete myself;
});
});
} else if (aCancelSubscription) {
// We can't synchronously delete ourselves, because we're inside one of
// the ReadClient callbacks and we need to outlive the callback's
// execution. Queue an async deletion on the Matter queue (where we are
Expand Down

0 comments on commit 2164354

Please sign in to comment.