plugin: Fix http_util_send_request to free resources 64/307364/1
authorSangYoun Kwak <sy.kwak@samsung.com>
Mon, 19 Feb 2024 02:21:53 +0000 (11:21 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 7 Mar 2024 10:21:37 +0000 (19:21 +0900)
In the function http_util_send_request, it was not freeing resources
which it allocated properly.
To make it to free resources properly, return statements are fixed to
'goto END;' statement.

Change-Id: Idd905ed10098a2403acf609d98c273b86ed72f4a
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/plugin/http_util.c

index 5bacc8aa225fa14770a69a02da4fc73a54d18c4d..11ba36bfa5338460d5cdbef867dc2a48c07a909d 100644 (file)
@@ -403,19 +403,29 @@ int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_he
 
        if (type == FMWUP_HTTP_GET) {
                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);
+               if (CURLE_OK != curl_ret_code) {
+                       _E("Failed to curl_easy_setopt with CURLOPT_HTTPGET : ret_code[%d]", curl_ret_code);
+                       ret = -EIO;
+                       goto END;
+               }
        } else if (type == FMWUP_HTTP_POST) {
                mime = curl_mime_init(curl);
-               retvm_if(!mime, -EIO, "curl_mime_init: Failed to init mime");
+               if (!mime) {
+                       _E("curl_mime_init: Failed to init mime");
+                       ret = -EIO;
+                       goto END;
+               }
 
                curl_ret_code = curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
                if (curl_ret_code != CURLE_OK) {
-                       curl_mime_free(mime);
                        _E("Failed to curl_easy_setopt with CURLOPT_MIMEPOST : ret_code[%d]", curl_ret_code);
-                       return -EIO;
+                       ret = -EIO;
+                       goto END;
                }
        } else {
-               return -1;
+               _E("Invalid http type: %d", type);
+               ret = -1;
+               goto END;
        }
 
        __curl_set_common_option(curl, (const char *)req_url, &response_header, &response_body);