Skip to content

Commit

Permalink
Don't touch member variables from async dispatch. (#21456)
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
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 21, 2023
1 parent 731b252 commit 7c85d4b
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 7c85d4b

Please sign in to comment.