diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 63a4b95eb96ff1..5c60e94986cd62 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -407,12 +407,14 @@ CHIP_ERROR ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchange { VerifyOrExit(apExchangeContext == mpExchangeCtx, err = CHIP_ERROR_INCORRECT_STATE); err = ProcessSubscribeResponse(std::move(aPayload)); + SuccessOrExit(err); - // Forget the context as SUBSCRIBE RESPONSE is the last message in SUBSCRIBE transaction and - // ExchangeContext::HandleMessage automatically closes a context if no other messages need to - // be sent or received. + // + // Null out the delegate and context as SubscribeResponse is the last message the Subscribe transaction and + // the exchange layer will automatically close the exchange. + // + mpExchangeCtx->SetDelegate(nullptr); mpExchangeCtx = nullptr; - SuccessOrExit(err); } else if (aPayloadHeader.HasMessageType(Protocols::InteractionModel::MsgType::StatusResponse)) {