@@ -146,6 +146,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
146
146
if (!_client->connect (url.host_ .c_str (), port))
147
147
{
148
148
DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
149
+ delete _client;
150
+ _client = nullptr ;
149
151
return static_cast <int >(Error::ServerConnectError);
150
152
}
151
153
@@ -176,6 +178,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
176
178
if (!is_header_complete)
177
179
{
178
180
DEBUG_ERROR (" %s: Error receiving HTTP header %s" , __FUNCTION__, is_http_header_timeout ? " (timeout)" :" " );
181
+ delete _client;
182
+ _client = nullptr ;
179
183
return static_cast <int >(Error::HttpHeaderError);
180
184
}
181
185
@@ -206,6 +210,8 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
206
210
if (!content_length_ptr)
207
211
{
208
212
DEBUG_ERROR (" %s: Failure to extract content length from http header" , __FUNCTION__);
213
+ delete _client;
214
+ _client = nullptr ;
209
215
return static_cast <int >(Error::ParseHttpHeader);
210
216
}
211
217
/* Find start of numerical value. */
@@ -233,17 +239,23 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
233
239
234
240
/* ... check for header download timeout ... */
235
241
if (is_ota_header_timeout) {
242
+ delete _client;
243
+ _client = nullptr ;
236
244
return static_cast <int >(Error::OtaHeaderTimeout);
237
245
}
238
246
239
247
/* ... then check if OTA header length field matches HTTP content length... */
240
248
if (_ota_header.header .len != (content_length_val - sizeof (_ota_header.header .len ) - sizeof (_ota_header.header .crc32 ))) {
249
+ delete _client;
250
+ _client = nullptr ;
241
251
return static_cast <int >(Error::OtaHeaderLength);
242
252
}
243
253
244
254
/* ... and OTA magic number */
245
255
if (_ota_header.header .magic_number != ARDUINO_ESP32_OTA_MAGIC)
246
256
{
257
+ delete _client;
258
+ _client = nullptr ;
247
259
return static_cast <int >(Error::OtaHeaterMagicNumber);
248
260
}
249
261
@@ -255,9 +267,13 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
255
267
256
268
if (_ota_size <= content_length_val - sizeof (_ota_header))
257
269
{
270
+ delete _client;
271
+ _client = nullptr ;
258
272
return static_cast <int >(Error::OtaDownload);
259
273
}
260
274
275
+ delete _client;
276
+ _client = nullptr ;
261
277
return _ota_size;
262
278
}
263
279
0 commit comments