FILE *fp = NULL;
CURL *curl = NULL;
- CURLcode err;
- int curl_ret_code = 0;
+ CURLcode err = CURLE_OK;
+ int ret_code = 0;
+ int curl_ret_code = CURLE_OK;
curl = curl_easy_init();
retvm_if(!curl, -EIO, "Failed to init curl");
#endif
fp = fopen(download_path, "wb");
+ if (fp == NULL) {
+ _E("Failed to open %s", download_path);
+ goto clean;
+ }
curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, download_url);
if (CURLE_OK != curl_ret_code) {
clean:
curl_easy_cleanup(curl);
- fclose(fp);
- if (CURLE_OK != curl_ret_code) {
- return -EIO;
- }
+ if (fp != NULL)
+ fclose(fp);
+ else
+ ret_code = -EIO;
+
+ if (CURLE_OK != curl_ret_code)
+ ret_code = -EIO;
#ifdef DOWNLOAD_MONITORING
int status;
_I("Failed to download file[%s, %d]", curl_easy_strerror(err), err);
if (remove(download_path) < 0)
_E("Failed to remove [%s]", download_path);
- return -EIO;
+ ret_code = -EIO;
}
- return 0;
+ return ret_code;
}
int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_header, char **res_body)