From f18bb61e58fb3d4501c0eb3a63587052b1126b3b Mon Sep 17 00:00:00 2001 From: Marcin Kajor Date: Wed, 14 Sep 2022 12:55:23 +0200 Subject: [PATCH] [nrfconnect] light-switch-app: fix the crash during CASE session resumption. Accessing DeviceProxy object in the application callback is redundant and leads to crash, because of modified lifetime of this object in Matter core. --- .../nrfconnect/main/BindingHandler.cpp | 15 +++------------ .../nrfconnect/main/include/BindingHandler.h | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/examples/light-switch-app/nrfconnect/main/BindingHandler.cpp b/examples/light-switch-app/nrfconnect/main/BindingHandler.cpp index 7b810e936ad37a..fd435cd0014243 100644 --- a/examples/light-switch-app/nrfconnect/main/BindingHandler.cpp +++ b/examples/light-switch-app/nrfconnect/main/BindingHandler.cpp @@ -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; @@ -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) { @@ -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; diff --git a/examples/light-switch-app/nrfconnect/main/include/BindingHandler.h b/examples/light-switch-app/nrfconnect/main/include/BindingHandler.h index bfad3f8e6fae3c..8a6849dacc8587 100644 --- a/examples/light-switch-app/nrfconnect/main/include/BindingHandler.h +++ b/examples/light-switch-app/nrfconnect/main/include/BindingHandler.h @@ -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() {