From 7d34bf77c4c10a088209933e7f1a3245a4f49ec6 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 16 Aug 2023 11:38:46 +0200 Subject: [PATCH] Make sure _client is deleted returning from download function --- src/Arduino_ESP32_OTA.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index a87cb3b..00f46b5 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -146,6 +146,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if (!_client->connect(url.host_.c_str(), port)) { DEBUG_ERROR("%s: Connection failure with OTA storage server %s", __FUNCTION__, url.host_.c_str()); + delete _client; + _client = nullptr; return static_cast(Error::ServerConnectError); } @@ -176,6 +178,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if (!is_header_complete) { DEBUG_ERROR("%s: Error receiving HTTP header %s", __FUNCTION__, is_http_header_timeout ? "(timeout)":""); + delete _client; + _client = nullptr; return static_cast(Error::HttpHeaderError); } @@ -206,6 +210,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if (!content_length_ptr) { DEBUG_ERROR("%s: Failure to extract content length from http header", __FUNCTION__); + delete _client; + _client = nullptr; return static_cast(Error::ParseHttpHeader); } /* Find start of numerical value. */ @@ -238,12 +244,16 @@ int Arduino_ESP32_OTA::download(const char * ota_url) /* ... then check if OTA header length field matches HTTP content length... */ if (_ota_header.header.len != (content_length_val - sizeof(_ota_header.header.len) - sizeof(_ota_header.header.crc32))) { + delete _client; + _client = nullptr; return static_cast(Error::OtaHeaderLength); } /* ... and OTA magic number */ if (_ota_header.header.magic_number != ARDUINO_ESP32_OTA_MAGIC) { + delete _client; + _client = nullptr; return static_cast(Error::OtaHeaterMagicNumber); } @@ -255,9 +265,13 @@ int Arduino_ESP32_OTA::download(const char * ota_url) if(_ota_size <= content_length_val - sizeof(_ota_header)) { + delete _client; + _client = nullptr; return static_cast(Error::OtaDownload); } + delete _client; + _client = nullptr; return _ota_size; }