From 01a89904cc39c3284e210754510e3556c358f6d7 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw@obs.cr>
Date: Mon, 17 Mar 2025 15:39:20 -0400
Subject: [PATCH] Thoroughly Shutdown The Stack On Non-Interactive Chip Command

When there is a non-interactive CHIP Command, be sure to completely
shutdown the stack. In the case where the stack is not completely
shutdown, it is impossible to run another CHIP Command from within the
same address space.
---
 examples/chip-tool/commands/common/CHIPCommand.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp
index 5401f907bc874d..0abcdb563ad9f7 100644
--- a/examples/chip-tool/commands/common/CHIPCommand.cpp
+++ b/examples/chip-tool/commands/common/CHIPCommand.cpp
@@ -225,6 +225,11 @@ void CHIPCommand::MaybeTearDownStack()
     {
         ShutdownCommissioner(commissioner.first);
     }
+    mCommissioners.clear();
+    sICDClientStorage.Shutdown();
+    sCheckInHandler.Shutdown();
+    sGroupDataProvider.Finish();
+    DeviceControllerFactory::GetInstance().Shutdown();
 
     StopTracing();
 }