From 96a2e925cf86b1c3a7343bd1efdbaf48844962e3 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 8 Jul 2024 09:21:46 -0700 Subject: [PATCH] Fix leak in HTTPSClient (#2256) Fixes #2254 The faked certificate was allocated but not deleted in certain cases. Make sure to clean up in the destructor. --- libraries/HTTPClient/src/HTTPClient.h | 6 +++++- libraries/WiFi/src/WiFiClientSecureBearSSL.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 3136200b..999279a4 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -179,7 +179,11 @@ typedef std::vector CookieJar; class HTTPClient { public: HTTPClient() = default; - ~HTTPClient() = default; + ~HTTPClient() { + if (_clientMade) { + delete _clientMade; + } + } HTTPClient(HTTPClient&&) = default; HTTPClient& operator=(HTTPClient&&) = default; diff --git a/libraries/WiFi/src/WiFiClientSecureBearSSL.cpp b/libraries/WiFi/src/WiFiClientSecureBearSSL.cpp index a3b59d8b..9bfefd97 100644 --- a/libraries/WiFi/src/WiFiClientSecureBearSSL.cpp +++ b/libraries/WiFi/src/WiFiClientSecureBearSSL.cpp @@ -123,6 +123,10 @@ WiFiClientSecureCtx::~WiFiClientSecureCtx() { _client->unref(); _client = nullptr; } + if (_esp32_ta) { + delete _esp32_ta; + } + _cipher_list = nullptr; // std::shared will free if last reference _freeSSL(); stack_thunk_del_ref();