@@ -108,15 +108,16 @@ int rp2040_connect_onOTARequest(char const * ota_url)
108108 port = 443 ;
109109 } else {
110110 DEBUG_ERROR (" %s: Failed to parse OTA URL %s" , __FUNCTION__, ota_url);
111+ fclose (file);
111112 return static_cast <int >(OTAError::RP2040_UrlParseError);
112113 }
113114
114115 mbed_watchdog_reset ();
115116
116117 if (!client->connect (url.host_ .c_str (), port))
117118 {
118- fclose (file);
119119 DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
120+ fclose (file);
120121 return static_cast <int >(OTAError::RP2040_ServerConnectError);
121122 }
122123
@@ -150,9 +151,10 @@ int rp2040_connect_onOTARequest(char const * ota_url)
150151 }
151152 }
152153
153- if (!is_header_complete) {
154- fclose (file);
154+ if (!is_header_complete)
155+ {
155156 DEBUG_ERROR (" %s: Error receiving HTTP header %s" , __FUNCTION__, is_http_header_timeout ? " (timeout)" :" " );
157+ fclose (file);
156158 return static_cast <int >(OTAError::RP2040_HttpHeaderError);
157159 }
158160
@@ -162,8 +164,8 @@ int rp2040_connect_onOTARequest(char const * ota_url)
162164 char const * content_length_ptr = strstr (http_header.c_str (), " Content-Length" );
163165 if (!content_length_ptr)
164166 {
165- fclose (file);
166167 DEBUG_ERROR (" %s: Failure to extract content length from http header" , __FUNCTION__);
168+ fclose (file);
167169 return static_cast <int >(OTAError::RP2040_ErrorParseHttpHeader);
168170 }
169171 /* Find start of numerical value. */
@@ -201,8 +203,8 @@ int rp2040_connect_onOTARequest(char const * ota_url)
201203 }
202204
203205 if (bytes_received != content_length_val) {
204- fclose (file);
205206 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);
206208 return static_cast <int >(OTAError::RP2040_HttpDataError);
207209 }
208210
0 commit comments