@@ -151,6 +151,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
151
151
if (!_client->connect (url.host_ .c_str (), port))
152
152
{
153
153
DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
154
+ delete _client;
155
+ _client = nullptr ;
154
156
return static_cast <int >(Error::ServerConnectError);
155
157
}
156
158
@@ -181,6 +183,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
181
183
if (!is_header_complete)
182
184
{
183
185
DEBUG_ERROR (" %s: Error receiving HTTP header %s" , __FUNCTION__, is_http_header_timeout ? " (timeout)" :" " );
186
+ delete _client;
187
+ _client = nullptr ;
184
188
return static_cast <int >(Error::HttpHeaderError);
185
189
}
186
190
@@ -211,6 +215,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
211
215
if (!content_length_ptr)
212
216
{
213
217
DEBUG_ERROR (" %s: Failure to extract content length from http header" , __FUNCTION__);
218
+ delete _client;
219
+ _client = nullptr ;
214
220
return static_cast <int >(Error::ParseHttpHeader);
215
221
}
216
222
/* Find start of numerical value. */
@@ -238,17 +244,23 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
238
244
239
245
/* ... check for header download timeout ... */
240
246
if (is_ota_header_timeout) {
247
+ delete _client;
248
+ _client = nullptr ;
241
249
return static_cast <int >(Error::OtaHeaderTimeout);
242
250
}
243
251
244
252
/* ... then check if OTA header length field matches HTTP content length... */
245
253
if (_ota_header.header .len != (content_length_val - sizeof (_ota_header.header .len ) - sizeof (_ota_header.header .crc32 ))) {
254
+ delete _client;
255
+ _client = nullptr ;
246
256
return static_cast <int >(Error::OtaHeaderLength);
247
257
}
248
258
249
259
/* ... and OTA magic number */
250
260
if (_ota_header.header .magic_number != ARDUINO_ESP32_OTA_MAGIC)
251
261
{
262
+ delete _client;
263
+ _client = nullptr ;
252
264
return static_cast <int >(Error::OtaHeaterMagicNumber);
253
265
}
254
266
@@ -260,9 +272,13 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
260
272
261
273
if (_ota_size <= content_length_val - sizeof (_ota_header))
262
274
{
275
+ delete _client;
276
+ _client = nullptr ;
263
277
return static_cast <int >(Error::OtaDownload);
264
278
}
265
279
280
+ delete _client;
281
+ _client = nullptr ;
266
282
return _ota_size;
267
283
}
268
284
0 commit comments