From dd11eaf9473ac223a80a78f7bb9a3f6148c15b16 Mon Sep 17 00:00:00 2001 From: Alami-Amine Date: Mon, 21 Oct 2024 21:34:14 +0200 Subject: [PATCH] Integrating comments --- src/protocols/secure_channel/PASESession.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/protocols/secure_channel/PASESession.cpp b/src/protocols/secure_channel/PASESession.cpp index 32a10060711164..5ea4389ded1739 100644 --- a/src/protocols/secure_channel/PASESession.cpp +++ b/src/protocols/secure_channel/PASESession.cpp @@ -232,18 +232,15 @@ CHIP_ERROR PASESession::Pair(SessionManager & sessionManager, uint32_t peerSetUp exit: if (err != CHIP_NO_ERROR) { - // If a failure happens in PASESession::Init, we need to ensure that the passed exchange context is closed to prevent - // resource leaks. - exchangeCtxt->Close(); - - // If a failure happens in SendPBKDFParamRequest, we need to Discard the exchange (mExchangeCtxt) so that Clear() doesn't - // try closing it. The exchange will handle that. - DiscardExchange(); + // If a failure happens before we have placed the incoming exchange into `mExchangeCtxt`, we need to make + // sure to close the exchange to fulfill our API contract. + if (!mExchangeCtxt.HasValue()) + { + exchangeCtxt->Close(); + } Clear(); ChipLogError(SecureChannel, "Failed during PASE session pairing request: %" CHIP_ERROR_FORMAT, err.Format()); MATTER_TRACE_COUNTER("PASEFail"); - // Do this last in case the delegate frees us. - NotifySessionEstablishmentError(err); } return err; }