From 225460009b110e0a0e34d5f93e8734193927f108 Mon Sep 17 00:00:00 2001 From: Jeff Tung <100387939+jtung-apple@users.noreply.github.com> Date: Fri, 29 Sep 2023 07:58:09 -0700 Subject: [PATCH] [Darwin] MTRBaseSubscriptionCallback mInterimReportBlock should be cancelled and nil-ed sooner for OnError case (#29500) --- .../Framework/CHIP/MTRBaseSubscriptionCallback.mm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm b/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm index 4b313d75c9e6b6..e498a1682d52aa 100644 --- a/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm +++ b/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm @@ -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; @@ -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]; @@ -71,10 +76,6 @@ void MTRBaseSubscriptionCallback::OnReportEnd() { - if (mInterimReportBlock) { - dispatch_block_cancel(mInterimReportBlock); - mInterimReportBlock = nil; - } ReportData(); if (mReportEndHandler) { mReportEndHandler();