From bd132eec091e7e53c5ce5ba4a289e69789b41dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Kr=C3=B3lik?= <66667989+Damian-Nordic@users.noreply.github.com> Date: Mon, 11 Jul 2022 21:57:01 +0200 Subject: [PATCH] Revert "[ota] Fix exchange context leak in OTA requestor (#20304)" (#20563) This reverts commit 757682e4a952f5c6772b7154fa4cabd9c4bf91f8. --- .../ota-requestor/DefaultOTARequestor.cpp | 8 +++----- .../ota-requestor/DefaultOTARequestor.h | 20 +++++++------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index 3f4cf67829c56d..bc7f857834b7cf 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -638,14 +638,12 @@ void DefaultOTARequestor::OnDownloadStateChanged(OTADownloader::State state, OTA { case OTADownloader::State::kComplete: mOtaRequestorDriver->UpdateDownloaded(); - mBdxMessenger.Reset(); break; case OTADownloader::State::kIdle: if (reason != OTAChangeReasonEnum::kSuccess) { RecordErrorUpdateState(CHIP_ERROR_CONNECTION_ABORTED, reason); } - mBdxMessenger.Reset(); break; default: break; @@ -825,10 +823,10 @@ CHIP_ERROR DefaultOTARequestor::StartDownload(OperationalDeviceProxy & devicePro Optional session = deviceProxy.GetSecureSession(); VerifyOrReturnError(session.HasValue(), CHIP_ERROR_INCORRECT_STATE); - chip::Messaging::ExchangeContext * exchangeCtx = exchangeMgr->NewContext(session.Value(), &mBdxMessenger); - VerifyOrReturnError(exchangeCtx != nullptr, CHIP_ERROR_NO_MEMORY); + mExchangeCtx = exchangeMgr->NewContext(session.Value(), &mBdxMessenger); + VerifyOrReturnError(mExchangeCtx != nullptr, CHIP_ERROR_NO_MEMORY); - mBdxMessenger.Init(mBdxDownloader, exchangeCtx); + mBdxMessenger.Init(mBdxDownloader, mExchangeCtx); mBdxDownloader->SetMessageDelegate(&mBdxMessenger); mBdxDownloader->SetStateDelegate(this); diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.h b/src/app/clusters/ota-requestor/DefaultOTARequestor.h index 99e9ae14c1b123..13c2f1bea9a504 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.h @@ -175,13 +175,6 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader:: mDownloader = downloader; } - void Reset() - { - VerifyOrReturn(mExchangeCtx != nullptr); - mExchangeCtx->Close(); - mExchangeCtx = nullptr; - } - private: chip::Messaging::ExchangeContext * mExchangeCtx; chip::BDXDownloader * mDownloader; @@ -299,12 +292,13 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader:: */ static void OnCommissioningCompleteRequestor(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg); - OTARequestorStorage * mStorage = nullptr; - OTARequestorDriver * mOtaRequestorDriver = nullptr; - CASESessionManager * mCASESessionManager = nullptr; - OnConnectedAction mOnConnectedAction = kQueryImage; - BDXDownloader * mBdxDownloader = nullptr; // TODO: this should be OTADownloader - BDXMessenger mBdxMessenger; // TODO: ideally this is held by the application + OTARequestorStorage * mStorage = nullptr; + OTARequestorDriver * mOtaRequestorDriver = nullptr; + CASESessionManager * mCASESessionManager = nullptr; + OnConnectedAction mOnConnectedAction = kQueryImage; + Messaging::ExchangeContext * mExchangeCtx = nullptr; + BDXDownloader * mBdxDownloader = nullptr; // TODO: this should be OTADownloader + BDXMessenger mBdxMessenger; // TODO: ideally this is held by the application uint8_t mUpdateTokenBuffer[kMaxUpdateTokenLen]; ByteSpan mUpdateToken; uint32_t mCurrentVersion = 0;