From e3d500b3a03f625f6cb16b165c9580bd47ccc4b0 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Tue, 18 May 2021 14:18:39 +0800 Subject: [PATCH] Fix ExchangeContext leak in chip_im_initiator (Fix: #6915) --- src/messaging/ExchangeMgr.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index 210238c29905a1..88cbf36a1e49f8 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -43,6 +43,10 @@ #include #include +#if CONFIG_DEVICE_LAYER +#include +#endif + using namespace chip::Encoding; using namespace chip::Inet; using namespace chip::System; @@ -94,6 +98,10 @@ CHIP_ERROR ExchangeManager::Init(SecureSessionMgr * sessionMgr) CHIP_ERROR ExchangeManager::Shutdown() { +// TODO(#6931): Lock guard is a temporary solution. Proper solution should be post chip shutdown function into chip thread +#if CONFIG_DEVICE_LAYER + DeviceLayer::PlatformMgr().LockChipStack(); +#endif mReliableMessageMgr.Shutdown(); mContextPool.ForEachActiveObject([](auto * ec) { @@ -109,6 +117,9 @@ CHIP_ERROR ExchangeManager::Shutdown() } mState = State::kState_NotInitialized; +#if CONFIG_DEVICE_LAYER + DeviceLayer::PlatformMgr().UnlockChipStack(); +#endif return CHIP_NO_ERROR; }