From 6022500ef29081b7463628221905d38e07908d14 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 2 Oct 2024 21:31:34 +0200 Subject: [PATCH] [Matter.framework] Wrap the MatterControllerFactory shutdown code that is runned with atexit into its own autorelease pool (#35878) --- src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm index 085d0a2c55ca6d..23643d6a52fa18 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm @@ -73,8 +73,12 @@ static bool sExitHandlerRegistered = false; static void ShutdownOnExit() { - MTR_LOG("ShutdownOnExit invoked on exit"); - [[MTRDeviceControllerFactory sharedInstance] stopControllerFactory]; + // Depending on the structure of the software, this code might execute *after* the main autorelease pool has exited. + // Therefore, it needs to be enclosed in its own autorelease pool. + @autoreleasepool { + MTR_LOG("ShutdownOnExit invoked on exit"); + [[MTRDeviceControllerFactory sharedInstance] stopControllerFactory]; + } } @interface MTRDeviceControllerFactoryParams ()