diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.h b/src/app/clusters/ota-requestor/DefaultOTARequestor.h index 6cbe1629b96d24..e0e45c2709af2e 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.h @@ -173,6 +173,12 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader:: void OnResponseTimeout(chip::Messaging::ExchangeContext * ec) override { ChipLogError(BDX, "exchange timed out"); + // Null out mExchangeCtx before calling OnDownloadTimeout, in case + // the downloader decides to call Reset() on us. If we don't, we + // will end up closing the exchange from Reset and then the caller + // will close it _again_ (see API documentation for + // OnResponseTimeout), which will lead to refcount underflow. + mExchangeCtx = nullptr; if (mDownloader != nullptr) { mDownloader->OnDownloadTimeout();