From 46b4649a8cb7242b5c7d39c37564b81074a6946f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 23 Sep 2022 09:44:30 -0400 Subject: [PATCH] Make sure to ignore setDeviceControllerDelegate calls on non-running controllers. (#22778) Otherwise we can end up with null-derefs trying to touch members that no longer exist. Fixes https://github.com/project-chip/connectedhomeip/issues/22776 --- src/darwin/Framework/CHIP/MTRDeviceController.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 43c2d0e7084fdc..221b4731d2dffb 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -535,7 +535,11 @@ - (void)removeDevice:(MTRDevice *)device - (void)setDeviceControllerDelegate:(id)delegate queue:(dispatch_queue_t)queue { + VerifyOrReturn([self checkIsRunning]); + dispatch_async(_chipWorkQueue, ^{ + VerifyOrReturn([self checkIsRunning]); + self->_deviceControllerDelegateBridge->setDelegate(self, delegate, queue); }); }