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
This commit is contained in:
MarkLee131 2026-03-30 00:59:24 +08:00 committed by Daniel Stenberg
parent 2c26cea5ec
commit 9fcc7e4c43
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 21 additions and 7 deletions

View file

@ -121,3 +121,4 @@ Andrew Kirillov <akirillo@uk.ibm.com>
Stephen Farrell <stephen.farrell@cs.tcd.ie> Stephen Farrell <stephen.farrell@cs.tcd.ie>
Calvin Ruocco <calvin.ruocco@vector.com> Calvin Ruocco <calvin.ruocco@vector.com>
Hamza Bensliman <benslimanhamza99@gmail.com> Hamza Bensliman <benslimanhamza99@gmail.com>
Kaixuan Li <kaixuan.li@ntu.edu.sg>

View file

@ -208,13 +208,20 @@ static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl,
if(!config->insecure_ok) { if(!config->insecure_ok) {
char *known = config->knownhosts; char *known = config->knownhosts;
if(!known) if(!known) {
known = findfile(".ssh/known_hosts", FALSE); 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) { if(known) {
result = my_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known); result = my_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known);
if(result) { if(result) {
config->knownhosts = NULL; config->knownhosts = NULL;
curl_free(known); curlx_free(known);
return result; return result;
} }
/* store it in global to avoid repeated checks */ /* store it in global to avoid repeated checks */

View file

@ -1267,10 +1267,16 @@ static ParameterError parse_ech(struct OperationConfig *config,
curlx_fclose(file); curlx_fclose(file);
if(err) if(err)
return err; return err;
config->ech_config = curl_maprintf("ecl:%s", tmpcfg); {
curlx_free(tmpcfg); char *tmp = curl_maprintf("ecl:%s", tmpcfg);
if(!config->ech_config) curlx_free(tmpcfg);
return PARAM_NO_MEM; 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 */ } /* file done */
} }
else { else {