From 2580849813e665fbeb2a67878df8e913e3523b2e Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 26 Oct 2022 12:03:01 -0400 Subject: [PATCH] Make sure there is only one state that an MTRControllerFactory with no controllers can be in. (#23348) We don't want to be in different states in the "started no controllers" and "started one controller and then shut it down" cases. --- src/darwin/Framework/CHIP/MTRControllerFactory.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/darwin/Framework/CHIP/MTRControllerFactory.mm b/src/darwin/Framework/CHIP/MTRControllerFactory.mm index 9539a8f6eabdee..3d77b893229d7b 100644 --- a/src/darwin/Framework/CHIP/MTRControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRControllerFactory.mm @@ -309,6 +309,14 @@ - (BOOL)startup:(MTRControllerFactoryParams *)startupParams return; } + // Make sure we don't leave a system state running while we have no + // controllers started. This is working around the fact that a system + // state is brought up live on factory init, and not when it comes time + // to actually start a controller, and does not actually clean itself up + // until its refcount (which starts as 0) goes to 0. + _controllerFactory->RetainSystemState(); + _controllerFactory->ReleaseSystemState(); + self->_isRunning = YES; });