Skip to content

Commit 1136472

Browse files
jtung-applepull[bot]
authored andcommitted
[Darwin] MTRBaseSubscriptionCallback mInterimReportBlock should be cancelled and nil-ed sooner for OnError case (#29500)
1 parent 837604c commit 1136472

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm

+6-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
// Reports attribute and event data if any exists
3636
void MTRBaseSubscriptionCallback::ReportData()
3737
{
38+
// At data reporting time, nil out scheduled or currently running interimReportBlock
39+
if (mInterimReportBlock) {
40+
dispatch_block_cancel(mInterimReportBlock); // no-op when running from mInterimReportBlock
41+
mInterimReportBlock = nil;
42+
}
43+
3844
__block NSArray * attributeReports = mAttributeReports;
3945
mAttributeReports = nil;
4046
auto attributeCallback = mAttributeReportCallback;
@@ -59,7 +65,6 @@
5965
}
6066

6167
mInterimReportBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
62-
mInterimReportBlock = nil;
6368
ReportData();
6469
// Allocate reports arrays to continue accumulation
6570
mAttributeReports = [NSMutableArray new];
@@ -71,10 +76,6 @@
7176

7277
void MTRBaseSubscriptionCallback::OnReportEnd()
7378
{
74-
if (mInterimReportBlock) {
75-
dispatch_block_cancel(mInterimReportBlock);
76-
mInterimReportBlock = nil;
77-
}
7879
ReportData();
7980
if (mReportEndHandler) {
8081
mReportEndHandler();

0 commit comments

Comments
 (0)