Skip to content

Commit

Permalink
[nrfconnect] light-switch-app: fix the crash during CASE session resu…
Browse files Browse the repository at this point in the history
…mption. (#22622)

Accessing DeviceProxy object in the application callback
is redundant and leads to crash, because of modified
lifetime of this object in Matter core.
  • Loading branch information
markaj-nordic authored Sep 16, 2022
1 parent b381ba8 commit d668dc2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
15 changes: 3 additions & 12 deletions examples/light-switch-app/nrfconnect/main/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ void BindingHandler::Init()
DeviceLayer::PlatformMgr().ScheduleWork(InitInternal);
}

void BindingHandler::OnInvokeCommandFailure(DeviceProxy * aDevice, BindingData & aBindingData, CHIP_ERROR aError)
void BindingHandler::OnInvokeCommandFailure(BindingData & aBindingData, CHIP_ERROR aError)
{
CHIP_ERROR error;

if (aError == CHIP_ERROR_TIMEOUT && !BindingHandler::GetInstance().mCaseSessionRecovered)
{
LOG_INF("Response timeout for invoked command, trying to recover CASE session.");
if (!aDevice)
return;

// Release current CASE session.
aDevice->Disconnect();

// Set flag to not try recover session multiple times.
BindingHandler::GetInstance().mCaseSessionRecovered = true;
Expand Down Expand Up @@ -85,9 +80,7 @@ void BindingHandler::OnOffProcessCommand(CommandId aCommandId, const EmberBindin
BindingHandler::GetInstance().mCaseSessionRecovered = false;
};

auto onFailure = [aDevice, dataRef = *data](CHIP_ERROR aError) mutable {
BindingHandler::OnInvokeCommandFailure(aDevice, dataRef, aError);
};
auto onFailure = [dataRef = *data](CHIP_ERROR aError) mutable { BindingHandler::OnInvokeCommandFailure(dataRef, aError); };

if (aDevice)
{
Expand Down Expand Up @@ -162,9 +155,7 @@ void BindingHandler::LevelControlProcessCommand(CommandId aCommandId, const Embe
BindingHandler::GetInstance().mCaseSessionRecovered = false;
};

auto onFailure = [aDevice, dataRef = *data](CHIP_ERROR aError) mutable {
BindingHandler::OnInvokeCommandFailure(aDevice, dataRef, aError);
};
auto onFailure = [dataRef = *data](CHIP_ERROR aError) mutable { BindingHandler::OnInvokeCommandFailure(dataRef, aError); };

CHIP_ERROR ret = CHIP_NO_ERROR;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BindingHandler
bool IsGroupBound();

static void SwitchWorkerHandler(intptr_t);
static void OnInvokeCommandFailure(chip::DeviceProxy * aDevice, BindingData & aBindingData, CHIP_ERROR aError);
static void OnInvokeCommandFailure(BindingData & aBindingData, CHIP_ERROR aError);

static BindingHandler & GetInstance()
{
Expand Down

0 comments on commit d668dc2

Please sign in to comment.