From 85053a567dbdfe358adb50b1e2dcac840322e29c Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Mon, 19 Feb 2024 11:21:53 +0900 Subject: [PATCH] plugin: Fix http_util_send_request to free resources 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 --- src/plugin/http_util.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugin/http_util.c b/src/plugin/http_util.c index 5bacc8a..11ba36b 100644 --- a/src/plugin/http_util.c +++ b/src/plugin/http_util.c @@ -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); -- 2.34.1