diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.mm b/src/darwin/Framework/CHIP/MTRBaseDevice.mm index c1a54ac7b6983d..05a0eb023a0c74 100644 --- a/src/darwin/Framework/CHIP/MTRBaseDevice.mm +++ b/src/darwin/Framework/CHIP/MTRBaseDevice.mm @@ -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); }); } }