From ea626671eaae4554d62f4ec19049ad95b050b6de Mon Sep 17 00:00:00 2001 From: shripad621git Date: Thu, 29 Aug 2024 17:12:07 +0530 Subject: [PATCH] Fixed the crash due to packet buffers running out of space in CommandHandlerImpl --- src/app/CommandHandlerImpl.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/CommandHandlerImpl.h b/src/app/CommandHandlerImpl.h index 55e356bcceb35a..00f61486d3e3a0 100644 --- a/src/app/CommandHandlerImpl.h +++ b/src/app/CommandHandlerImpl.h @@ -294,7 +294,13 @@ class CommandHandlerImpl : public CommandHandler { return CHIP_NO_ERROR; } - ReturnErrorOnFailure(RollbackResponse()); + // Here the err from previous step is returned intentionally if RollBackResonse fails due to + // running out of packet buffers i.e due to CHIP_ERROR_NO_MEMORY in AllocateBuffer() and + // fails to set the mRollBackBackupValid. + if (RollbackResponse() != CHIP_NO_ERROR) + { + return err; + } // If we failed to add a command due to lack of space in the // packet, we will make another attempt to add the response using // an additional InvokeResponseMessage.