Skip to content

Commit 6a06b25

Browse files
committed
Make sure _client is deleted returning from download function
1 parent 0ebe3c2 commit 6a06b25

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
@@ -151,6 +151,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
151151
if (!_client->connect(url.host_.c_str(), port))
152152
{
153153
DEBUG_ERROR("%s: Connection failure with OTA storage server %s", __FUNCTION__, url.host_.c_str());
154+
delete _client;
155+
_client = nullptr;
154156
return static_cast<int>(Error::ServerConnectError);
155157
}
156158

@@ -181,6 +183,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
181183
if (!is_header_complete)
182184
{
183185
DEBUG_ERROR("%s: Error receiving HTTP header %s", __FUNCTION__, is_http_header_timeout ? "(timeout)":"");
186+
delete _client;
187+
_client = nullptr;
184188
return static_cast<int>(Error::HttpHeaderError);
185189
}
186190

@@ -211,6 +215,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
211215
if (!content_length_ptr)
212216
{
213217
DEBUG_ERROR("%s: Failure to extract content length from http header", __FUNCTION__);
218+
delete _client;
219+
_client = nullptr;
214220
return static_cast<int>(Error::ParseHttpHeader);
215221
}
216222
/* Find start of numerical value. */
@@ -238,17 +244,23 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
238244

239245
/* ... check for header download timeout ... */
240246
if (is_ota_header_timeout) {
247+
delete _client;
248+
_client = nullptr;
241249
return static_cast<int>(Error::OtaHeaderTimeout);
242250
}
243251

244252
/* ... then check if OTA header length field matches HTTP content length... */
245253
if (_ota_header.header.len != (content_length_val - sizeof(_ota_header.header.len) - sizeof(_ota_header.header.crc32))) {
254+
delete _client;
255+
_client = nullptr;
246256
return static_cast<int>(Error::OtaHeaderLength);
247257
}
248258

249259
/* ... and OTA magic number */
250260
if (_ota_header.header.magic_number != ARDUINO_ESP32_OTA_MAGIC)
251261
{
262+
delete _client;
263+
_client = nullptr;
252264
return static_cast<int>(Error::OtaHeaterMagicNumber);
253265
}
254266

@@ -260,9 +272,13 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
260272

261273
if(_ota_size <= content_length_val - sizeof(_ota_header))
262274
{
275+
delete _client;
276+
_client = nullptr;
263277
return static_cast<int>(Error::OtaDownload);
264278
}
265279

280+
delete _client;
281+
_client = nullptr;
266282
return _ota_size;
267283
}
268284

0 commit comments

Comments
 (0)