Skip to content

Commit

Permalink
Fix _InitChipStack() initialization order. (project-chip#11374)
Browse files Browse the repository at this point in the history
#### Problem

`ConfigurationMgr().Init()` indirectly uses the System layer,
which has not yet been initialized, in its ‘fail-safe armed’ case.

Fixes project-chip#5336 TestPlatformMgr occasionally crashes on Linux

#### Change overview

Initialize Configuration Manager after the System layer.

#### Testing

Confirmed on Linux that adding `fail-safe-armed=1` to
`/tmp/chip_config.ini` reliably triggers the `TestPlatformMgr`
crash on master, but not after this change.

Relying on CI to confirm that there are no unexpected side effects
of changing the initialization order. (There should be none, since
System::Layer does not depend on ConfigurationMgr.)
  • Loading branch information
kpschoedel authored Nov 3, 2021
1 parent 0a53b50 commit 249ccbc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/include/platform/internal/GenericPlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_InitChipStack()
}
SuccessOrExit(err);

err = ConfigurationMgr().Init();
// Initialize the CHIP system layer.
err = SystemLayer().Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Configuration Manager initialization failed: %s", ErrorStr(err));
ChipLogError(DeviceLayer, "SystemLayer initialization failed: %s", ErrorStr(err));
}
SuccessOrExit(err);

// Initialize the CHIP system layer.
err = SystemLayer().Init();
// Initialize the Configuration Manager.
err = ConfigurationMgr().Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "SystemLayer initialization failed: %s", ErrorStr(err));
ChipLogError(DeviceLayer, "Configuration Manager initialization failed: %s", ErrorStr(err));
}
SuccessOrExit(err);

Expand Down

0 comments on commit 249ccbc

Please sign in to comment.