File tree 1 file changed +13
-4
lines changed
src/darwin/Framework/CHIP
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 138
138
mOnDoneHandler = nil ;
139
139
dispatch_async (mQueue , ^{
140
140
callback (err);
141
- if (onDoneHandler) {
142
- onDoneHandler ();
143
- }
144
141
});
145
142
146
- if (aCancelSubscription) {
143
+ if (onDoneHandler) {
144
+ // To guarantee the async onDoneHandler call is made before
145
+ // deletion, so that clean up can happen while the callback
146
+ // object is still alive (and therefore cluster cache), queue
147
+ // deletion after calling the onDoneHandler
148
+ mHaveQueuedDeletion = true ;
149
+ dispatch_async (mQueue , ^{
150
+ onDoneHandler ();
151
+ dispatch_async (DeviceLayer::PlatformMgrImpl ().GetWorkQueue (), ^{
152
+ delete myself;
153
+ });
154
+ });
155
+ } else if (aCancelSubscription) {
147
156
// We can't synchronously delete ourselves, because we're inside one of
148
157
// the ReadClient callbacks and we need to outlive the callback's
149
158
// execution. Queue an async deletion on the Matter queue (where we are
You can’t perform that action at this time.
0 commit comments