Skip to content

Commit

Permalink
[Darwin] MTRBaseSubscriptionCallback mInterimReportBlock should be ca…
Browse files Browse the repository at this point in the history
…ncelled and nil-ed sooner for OnError case (#29500)
  • Loading branch information
jtung-apple authored and pull[bot] committed Mar 4, 2024
1 parent ef059fc commit 2254600
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
// Reports attribute and event data if any exists
void MTRBaseSubscriptionCallback::ReportData()
{
// At data reporting time, nil out scheduled or currently running interimReportBlock
if (mInterimReportBlock) {
dispatch_block_cancel(mInterimReportBlock); // no-op when running from mInterimReportBlock
mInterimReportBlock = nil;
}

__block NSArray * attributeReports = mAttributeReports;
mAttributeReports = nil;
auto attributeCallback = mAttributeReportCallback;
Expand All @@ -59,7 +65,6 @@
}

mInterimReportBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
mInterimReportBlock = nil;
ReportData();
// Allocate reports arrays to continue accumulation
mAttributeReports = [NSMutableArray new];
Expand All @@ -71,10 +76,6 @@

void MTRBaseSubscriptionCallback::OnReportEnd()
{
if (mInterimReportBlock) {
dispatch_block_cancel(mInterimReportBlock);
mInterimReportBlock = nil;
}
ReportData();
if (mReportEndHandler) {
mReportEndHandler();
Expand Down

0 comments on commit 2254600

Please sign in to comment.