Skip to content

Commit

Permalink
Don't touch member variables from async dispatch. (#21456) (#21506)
Browse files Browse the repository at this point in the history
We were null-checking members, then calling them from an async block,
by which point they might be null.

Fixes #21453

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
woody-apple and bzbarsky-apple authored Aug 2, 2022
1 parent fa7686f commit 7571349
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1384,16 +1384,20 @@ - (instancetype)initWithPath:(const ConcreteEventPath &)path
{
__block NSArray * attributeReports = mAttributeReports;
mAttributeReports = nil;
__block auto attributeCallback = mAttributeReportCallback;

__block NSArray * eventReports = mEventReports;
mEventReports = nil;
if (mAttributeReportCallback && attributeReports.count) {
__block auto eventCallback = mEventReportCallback;

if (attributeCallback != nil && attributeReports.count) {
dispatch_async(mQueue, ^{
mAttributeReportCallback(attributeReports);
attributeCallback(attributeReports);
});
}
if (mEventReportCallback && eventReports.count) {
if (eventCallback != nil && eventReports.count) {
dispatch_async(mQueue, ^{
mEventReportCallback(eventReports);
eventCallback(eventReports);
});
}
}
Expand Down

0 comments on commit 7571349

Please sign in to comment.