Fix coverity issue - resource leak 30/259830/1 accepted/tizen/6.5/unified/20211028.120343 accepted/tizen/unified/20210615.215232 submit/tizen/20210615.154137 submit/tizen_6.5/20211028.162501 tizen_6.5.m2_release
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 15 Jun 2021 10:12:53 +0000 (12:12 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 15 Jun 2021 10:12:53 +0000 (12:12 +0200)
Change-Id: Icf860015ab0ae692a14ce2c46af67770f2b30a7c

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

index 7b826dc07d760a74ad394fd07dce420721914539..05b4b3f4a7e839a14fc3c3846d2471a5fcc43611 100644 (file)
@@ -255,7 +255,8 @@ int http_util_check_request_to_fota(const char *uid,
        retvm_if(!curl, -EIO, "Failed to init curl");
 
        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);
+       retvmf_if(CURLE_OK != curl_ret_code, -EIO, curl_easy_cleanup(curl),
+                 "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);
@@ -265,7 +266,8 @@ int http_util_check_request_to_fota(const char *uid,
        g_free(tmp_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);
+       retvmf_if(CURLE_OK != curl_ret_code, -EIO, curl_easy_cleanup(curl),
+                 "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);
index 48865b238c40734af98e14bace818fc72e150089..e09a833a6a196e8de10c19551ec53e7ee7efe8dd 100644 (file)
@@ -42,6 +42,9 @@ extern "C"
 #define retvm_if(expr, val, fmt, arg...) \
        do { if (expr) { _E(fmt, ##arg); return (val); } } while (0)
 
+#define retvmf_if(expr, val, func, fmt, arg...) \
+       do { if (expr) { _E(fmt, ##arg); func; return (val); } } while (0)
+
 #ifdef __cplusplus
 }
 #endif