@@ -108,15 +108,16 @@ int rp2040_connect_onOTARequest(char const * ota_url)
108
108
port = 443 ;
109
109
} else {
110
110
DEBUG_ERROR (" %s: Failed to parse OTA URL %s" , __FUNCTION__, ota_url);
111
+ fclose (file);
111
112
return static_cast <int >(OTAError::RP2040_UrlParseError);
112
113
}
113
114
114
115
mbed_watchdog_reset ();
115
116
116
117
if (!client->connect (url.host_ .c_str (), port))
117
118
{
118
- fclose (file);
119
119
DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
120
+ fclose (file);
120
121
return static_cast <int >(OTAError::RP2040_ServerConnectError);
121
122
}
122
123
@@ -150,9 +151,10 @@ int rp2040_connect_onOTARequest(char const * ota_url)
150
151
}
151
152
}
152
153
153
- if (!is_header_complete) {
154
- fclose (file);
154
+ if (!is_header_complete)
155
+ {
155
156
DEBUG_ERROR (" %s: Error receiving HTTP header %s" , __FUNCTION__, is_http_header_timeout ? " (timeout)" :" " );
157
+ fclose (file);
156
158
return static_cast <int >(OTAError::RP2040_HttpHeaderError);
157
159
}
158
160
@@ -162,8 +164,8 @@ int rp2040_connect_onOTARequest(char const * ota_url)
162
164
char const * content_length_ptr = strstr (http_header.c_str (), " Content-Length" );
163
165
if (!content_length_ptr)
164
166
{
165
- fclose (file);
166
167
DEBUG_ERROR (" %s: Failure to extract content length from http header" , __FUNCTION__);
168
+ fclose (file);
167
169
return static_cast <int >(OTAError::RP2040_ErrorParseHttpHeader);
168
170
}
169
171
/* Find start of numerical value. */
@@ -201,8 +203,8 @@ int rp2040_connect_onOTARequest(char const * ota_url)
201
203
}
202
204
203
205
if (bytes_received != content_length_val) {
204
- fclose (file);
205
206
DEBUG_ERROR (" %s: Error receiving HTTP data %s (%d bytes received, %d expected)" , __FUNCTION__, is_http_data_timeout ? " (timeout)" :" " , bytes_received, content_length_val);
207
+ fclose (file);
206
208
return static_cast <int >(OTAError::RP2040_HttpDataError);
207
209
}
208
210
0 commit comments