From 3120ae83570ab589b1159222cf8f4f873942c2de Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 15 Apr 2021 16:48:46 +0200 Subject: [PATCH] The ExchangeContext is not closed once a message has been dispatched via CHIPDeviceController to a CHIPDevice (#6045) --- src/controller/CHIPDeviceController.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index ccd2b2db684375..f47741d652fe55 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -391,16 +391,20 @@ CHIP_ERROR DeviceController::ServiceEventSignal() void DeviceController::OnMessageReceived(Messaging::ExchangeContext * ec, const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, System::PacketBufferHandle msgBuf) { - VerifyOrReturn(mState == State::Initialized, ChipLogError(Controller, "OnMessageReceived was called in incorrect state")); + uint16_t index; - VerifyOrReturn(packetHeader.GetSourceNodeId().HasValue(), - ChipLogError(Controller, "OnMessageReceived was called for unknown source node")); + VerifyOrExit(mState == State::Initialized, ChipLogError(Controller, "OnMessageReceived was called in incorrect state")); - uint16_t index = FindDeviceIndex(packetHeader.GetSourceNodeId().Value()); - VerifyOrReturn(index < kNumMaxActiveDevices, - ChipLogError(Controller, "OnMessageReceived was called for unknown device object")); + VerifyOrExit(packetHeader.GetSourceNodeId().HasValue(), + ChipLogError(Controller, "OnMessageReceived was called for unknown source node")); + + index = FindDeviceIndex(packetHeader.GetSourceNodeId().Value()); + VerifyOrExit(index < kNumMaxActiveDevices, ChipLogError(Controller, "OnMessageReceived was called for unknown device object")); mActiveDevices[index].OnMessageReceived(packetHeader, payloadHeader, std::move(msgBuf)); + +exit: + ec->Close(); } void DeviceController::OnResponseTimeout(Messaging::ExchangeContext * ec)