From 9fcc7e4c43cea795f343e3308278a9dba61431d2 Mon Sep 17 00:00:00 2001 From: MarkLee131 Date: Mon, 30 Mar 2026 00:59:24 +0800 Subject: [PATCH] tool: fix two more allocator mismatches memory allocated by libcurl (curl_maprintf) must be freed with curl_free(), and memory allocated by the tool (curlx_strdup via findfile) must be freed with curlx_free(). - tool_cfgable: ech_config is allocated with curl_maprintf, free it with curl_free() instead of tool_safefree() - config2setopts: known hosts from findfile() is allocated with curlx_strdup, free it with curlx_free() instead of curl_free() Follow-up to b71973c115 Closes #21150 --- .mailmap | 1 + src/config2setopts.c | 13 ++++++++++--- src/tool_getparam.c | 14 ++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.mailmap b/.mailmap index d4e547b9ed..d8558a2ec3 100644 --- a/.mailmap +++ b/.mailmap @@ -121,3 +121,4 @@ Andrew Kirillov Stephen Farrell Calvin Ruocco Hamza Bensliman +Kaixuan Li diff --git a/src/config2setopts.c b/src/config2setopts.c index 1a82edeb70..47078884b0 100644 --- a/src/config2setopts.c +++ b/src/config2setopts.c @@ -208,13 +208,20 @@ static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl, if(!config->insecure_ok) { char *known = config->knownhosts; - if(!known) - known = findfile(".ssh/known_hosts", FALSE); + if(!known) { + char *found = findfile(".ssh/known_hosts", FALSE); + if(found) { + known = curlx_strdup(found); + curl_free(found); + if(!known) + return CURLE_OUT_OF_MEMORY; + } + } if(known) { result = my_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known); if(result) { config->knownhosts = NULL; - curl_free(known); + curlx_free(known); return result; } /* store it in global to avoid repeated checks */ diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 791a55c790..225defc429 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -1267,10 +1267,16 @@ static ParameterError parse_ech(struct OperationConfig *config, curlx_fclose(file); if(err) return err; - config->ech_config = curl_maprintf("ecl:%s", tmpcfg); - curlx_free(tmpcfg); - if(!config->ech_config) - return PARAM_NO_MEM; + { + char *tmp = curl_maprintf("ecl:%s", tmpcfg); + curlx_free(tmpcfg); + if(!tmp) + return PARAM_NO_MEM; + config->ech_config = curlx_strdup(tmp); + curl_free(tmp); + if(!config->ech_config) + return PARAM_NO_MEM; + } } /* file done */ } else {