Fix coverity issue 38/225238/2 accepted/tizen/unified/20200218.145813 submit/tizen/20200218.095658
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Tue, 18 Feb 2020 09:07:51 +0000 (18:07 +0900)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Tue, 18 Feb 2020 09:08:58 +0000 (18:08 +0900)
- remove resource leak in fp

Change-Id: I1ad0129626d5438195b26448acb9c91c03b3c864
Signed-off-by: Jeon Sang-Heon <sh95.jeon@samsung.com>
src/plugin/http_util.c

index c428512ab9af8759e756f3f3e1d253a9fa003cb4..18494859e6f8b1be2cbd3621ba219dc7bc5f6c56 100644 (file)
@@ -334,19 +334,33 @@ int http_util_download_file(const char *download_url, const char *download_path,
        fp = fopen(download_path, "wb");
 
        curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, download_url);
-       retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_URL : ret_code[%d]", curl_ret_code);
+       if (CURLE_OK != curl_ret_code) {
+               _E("Failed to curl_easy_setopt with CURLOPT_URL : ret_code[%d]", curl_ret_code);
+               goto clean;
+       }
 
        curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
-       retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_WRITEFUNCTION : ret_code[%d]", curl_ret_code);
+       if (CURLE_OK != curl_ret_code) {
+               _E("Failed to curl_easy_setopt with CURLOPT_WRITEFUNCTION : ret_code[%d]", curl_ret_code);
+               goto clean;
+       }
 
        curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
-       retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_WRITEDATA : ret_code[%d]", curl_ret_code);
+       if (CURLE_OK != curl_ret_code) {
+               _E("Failed to curl_easy_setopt with CURLOPT_WRITEDATA : ret_code[%d]", curl_ret_code);
+               goto clean;
+       }
 
        err = curl_easy_perform(curl);
 
+clean:
        curl_easy_cleanup(curl);
        fclose(fp);
 
+       if (CURLE_OK != curl_ret_code) {
+               return -EIO;
+       }
+
 #ifdef DOWNLOAD_MONITORING
        int status;
        pthread_join(p_thread, (void **)&status);