Skip to content

Commit a6eb0a8

Browse files
committed
Make sure _client is deleted returning from download function
1 parent 9c51acf commit a6eb0a8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Arduino_ESP32_OTA.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
146146
if (!_client->connect(url.host_.c_str(), port))
147147
{
148148
DEBUG_ERROR("%s: Connection failure with OTA storage server %s", __FUNCTION__, url.host_.c_str());
149+
delete _client;
150+
_client = nullptr;
149151
return static_cast<int>(Error::ServerConnectError);
150152
}
151153

@@ -176,6 +178,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
176178
if (!is_header_complete)
177179
{
178180
DEBUG_ERROR("%s: Error receiving HTTP header %s", __FUNCTION__, is_http_header_timeout ? "(timeout)":"");
181+
delete _client;
182+
_client = nullptr;
179183
return static_cast<int>(Error::HttpHeaderError);
180184
}
181185

@@ -206,6 +210,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
206210
if (!content_length_ptr)
207211
{
208212
DEBUG_ERROR("%s: Failure to extract content length from http header", __FUNCTION__);
213+
delete _client;
214+
_client = nullptr;
209215
return static_cast<int>(Error::ParseHttpHeader);
210216
}
211217
/* Find start of numerical value. */
@@ -233,17 +239,23 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
233239

234240
/* ... check for header download timeout ... */
235241
if (is_ota_header_timeout) {
242+
delete _client;
243+
_client = nullptr;
236244
return static_cast<int>(Error::OtaHeaderTimeout);
237245
}
238246

239247
/* ... then check if OTA header length field matches HTTP content length... */
240248
if (_ota_header.header.len != (content_length_val - sizeof(_ota_header.header.len) - sizeof(_ota_header.header.crc32))) {
249+
delete _client;
250+
_client = nullptr;
241251
return static_cast<int>(Error::OtaHeaderLength);
242252
}
243253

244254
/* ... and OTA magic number */
245255
if (_ota_header.header.magic_number != ARDUINO_ESP32_OTA_MAGIC)
246256
{
257+
delete _client;
258+
_client = nullptr;
247259
return static_cast<int>(Error::OtaHeaterMagicNumber);
248260
}
249261

@@ -255,9 +267,13 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
255267

256268
if(_ota_size <= content_length_val - sizeof(_ota_header))
257269
{
270+
delete _client;
271+
_client = nullptr;
258272
return static_cast<int>(Error::OtaDownload);
259273
}
260274

275+
delete _client;
276+
_client = nullptr;
261277
return _ota_size;
262278
}
263279

0 commit comments

Comments
 (0)