Fix: fix coverity issue 77/223577/1
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 31 Jan 2020 02:30:46 +0000 (11:30 +0900)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 31 Jan 2020 02:48:56 +0000 (11:48 +0900)
- modify uncatched return code from curl_easy_setopt
- modify misused G_FREE to G_FREE

Change-Id: Ia4bfd345a545d9c2043d60e6ca50f3dcf1e88a1c

src/plugin/http_util.c
src/plugin/plugin.c

index 498fa1ed35a9ac9ba08a919509a318029b835002..c428512ab9af8759e756f3f3e1d253a9fa003cb4 100644 (file)
@@ -91,7 +91,10 @@ static void __curl_set_request_headers(CURL *curl)
        header = curl_slist_append(header, tmp_header);
        g_free(tmp_header);
 
-       curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
+       int curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
+       if (CURLE_OK != curl_ret_code) {
+               _E("curl_easy_setopt: CURLOPT_HTTPHEADER failed!! curl_ret_code[%d]", curl_ret_code);
+       }
 }
 
 static size_t __gather_data(void *downloaded_data,
@@ -246,11 +249,13 @@ int http_util_check_request_to_fota(const char *uid,
        char *tmp_header = NULL;
        char *req_url = NULL;
        char query[128];
+       int curl_ret_code = 0;
 
        curl = curl_easy_init();
        retvm_if(!curl, -EIO, "Failed to init curl");
 
-       curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+       curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+       retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPGET : ret_code[%d]", curl_ret_code);
 
        tmp_header = g_strconcat("X-IOT-UID: ", uid, NULL);
        header = curl_slist_append(header, tmp_header);
@@ -259,7 +264,8 @@ int http_util_check_request_to_fota(const char *uid,
        header = curl_slist_append(header, tmp_header);
        g_free(tmp_header);
 
-       curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
+       curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
+       retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPHEADER : ret_code[%d]", curl_ret_code);
 
        snprintf(query, sizeof(query), "?deviceType=%s&currentVersion=%s", device_type, current_version);
        req_url = g_strconcat(STDM_URL, query, NULL);
@@ -305,6 +311,7 @@ int http_util_download_file(const char *download_url, const char *download_path,
        FILE *fp = NULL;
        CURL *curl = NULL;
        CURLcode err;
+       int curl_ret_code = 0;
 
        curl = curl_easy_init();
        retvm_if(!curl, -EIO, "Failed to init curl");
@@ -326,9 +333,14 @@ int http_util_download_file(const char *download_url, const char *download_path,
 
        fp = fopen(download_path, "wb");
 
-       curl_easy_setopt(curl, CURLOPT_URL, download_url);
-       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
-       curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+       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);
+
+       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);
+
+       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);
 
        err = curl_easy_perform(curl);
 
@@ -357,6 +369,7 @@ int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_he
        GByteArray *response_header = NULL;
        GByteArray *response_body= NULL;
        CURLcode err;
+       int curl_ret_code = 0;
 
        curl = curl_easy_init();
        retvm_if(!curl, -EIO, "Failed to init curl");
@@ -364,9 +377,11 @@ int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_he
        __curl_set_request_headers(curl);
 
        if (type == FMWUP_HTTP_GET) {
-               curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+               curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+               retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPGET : ret_code[%d]", curl_ret_code);
        } else if (type == FMWUP_HTTP_POST) {
-               curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
+               curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
+               retvm_if(CURLE_OK != curl_ret_code, -EIO, "Failed to curl_easy_setopt with CURLOPT_HTTPPOST : ret_code[%d]", curl_ret_code);
        } else {
                return -1;
        }
index c37d41d6ee57281e4c9fcd9085bd51186227eeef..13e6efd7827e8f77897bf68df4a5a7a3c2685dc9 100644 (file)
@@ -666,7 +666,7 @@ API int update_control_download_package(void)
        package_downloaded = true;
 
 exit:
-       G_FREE(app_path);
+       free(app_path);
        G_FREE(download_url);
        G_FREE(download_path);
 
@@ -702,7 +702,7 @@ API int update_control_do_update(void)
        path = g_strconcat(app_path, FIRMWARE_FILE_NAME, NULL);
        if (!path) {
                _E("Failed to g_strconcat");
-               G_FREE(app_path);
+               free(app_path);
                return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
        }
 
@@ -715,7 +715,7 @@ API int update_control_do_update(void)
        /* Should be unreachable */
        _E("Update reboot timed out");
 
-       G_FREE(app_path);
+       free(app_path);
        G_FREE(path);
 
        return UPDATE_CONTROL_ERROR_TIMED_OUT;