Skip to content

Commit

Permalink
Avoid crash in reporting::Engine::ScheduleRun() (#13093)
Browse files Browse the repository at this point in the history
#### Problem

`reporting::Engine::ScheduleRun()` crashes if invoked after
`SessionManager` has shut down.

#### Change overview

Check pointers.

#### Testing

Verified using pending PR #13060 with
```
server start
server stop
exit
```
which crashes without this change.
  • Loading branch information
kpschoedel authored and pull[bot] committed Oct 16, 2023
1 parent 9a255c3 commit 1175663
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,24 @@ CHIP_ERROR Engine::ScheduleRun()
return CHIP_NO_ERROR;
}

if (InteractionModelEngine::GetInstance()->GetExchangeManager() != nullptr)
Messaging::ExchangeManager * exchangeManager = InteractionModelEngine::GetInstance()->GetExchangeManager();
if (exchangeManager == nullptr)
{
mRunScheduled = true;
return InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->ScheduleWork(Run,
this);
return CHIP_ERROR_INCORRECT_STATE;
}
else
SessionManager * sessionManager = exchangeManager->GetSessionManager();
if (sessionManager == nullptr)
{
return CHIP_ERROR_INCORRECT_STATE;
}
System::Layer * systemLayer = sessionManager->SystemLayer();
if (systemLayer == nullptr)
{
return CHIP_ERROR_INCORRECT_STATE;
}
ReturnErrorOnFailure(systemLayer->ScheduleWork(Run, this));
mRunScheduled = true;
return CHIP_NO_ERROR;
}

void Engine::Run()
Expand Down

0 comments on commit 1175663

Please sign in to comment.