Skip to content

Commit

Permalink
Fix DeviceControllerSystemState shutdown order
Browse files Browse the repository at this point in the history
#### Problem

Instance of project-chip#11880 Possible use of destroyed pool objects

`mTransportMgr` continues to hold `UDPEndPoint`s after
Inet is shut down via `PlatformMgr().Shutdown()`.

#### Change overview

- Shut down the `TransportMgr` before `PlatformMgr().Shutdown()`.

#### Testing

CI; no changes to functionality.
  • Loading branch information
kpschoedel committed Dec 1, 2021
1 parent 31156c4 commit f3a7eac
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ CHIP_ERROR DeviceControllerSystemState::Shutdown()
// Shut down the interaction model
app::InteractionModelEngine::GetInstance()->Shutdown();

// Shut down the TransportMgr. This holds Inet::UDPEndPoints so it must be shut down
// before PlatformMgr().Shutdown() shuts down Inet.
if (mTransportMgr != nullptr)
{
mTransportMgr->Close();
chip::Platform::Delete(mTransportMgr);
mTransportMgr = nullptr;
}

#if CONFIG_DEVICE_LAYER
//
// We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(),
Expand All @@ -247,11 +256,6 @@ CHIP_ERROR DeviceControllerSystemState::Shutdown()

mSystemLayer = nullptr;
mInetLayer = nullptr;
if (mTransportMgr != nullptr)
{
chip::Platform::Delete(mTransportMgr);
mTransportMgr = nullptr;
}

if (mMessageCounterManager != nullptr)
{
Expand Down

0 comments on commit f3a7eac

Please sign in to comment.