tidy-up: rename Curl_safefree()/tool_safefree() to curlx_safefree()

To sync names for the same macro logic between lib and src, and to move
it to the curlx namespace, to match `curlx_free()` that it's calling.

Closes #21151
This commit is contained in:
Viktor Szakats 2026-03-30 01:54:10 +02:00
parent 2b3dfb4ad4
commit 0df6c01db3
No known key found for this signature in database
72 changed files with 494 additions and 500 deletions

View file

@ -187,7 +187,7 @@ static char *parse_filename(const char *ptr, size_t len, char stop)
if(q) {
p = q + 1;
if(!*p) {
tool_safefree(copy);
curlx_safefree(copy);
return NULL;
}
}
@ -199,7 +199,7 @@ static char *parse_filename(const char *ptr, size_t len, char stop)
if(q) {
p = q + 1;
if(!*p) {
tool_safefree(copy);
curlx_safefree(copy);
return NULL;
}
}
@ -220,7 +220,7 @@ static char *parse_filename(const char *ptr, size_t len, char stop)
{
char *sanitized;
SANITIZEcode sc = sanitize_file_name(&sanitized, copy, 0);
tool_safefree(copy);
curlx_safefree(copy);
if(sc)
return NULL;
copy = sanitized;
@ -309,7 +309,7 @@ static size_t content_disposition(const char *str, const char *end,
return CURL_WRITEFUNC_ERROR;
}
if(outs->alloc_filename)
tool_safefree(outs->filename);
curlx_safefree(outs->filename);
if(per->config->output_dir) {
char *f = curl_maprintf("%s/%s", per->config->output_dir,
@ -364,7 +364,7 @@ static size_t content_disposition(const char *str, const char *end,
return CURL_WRITEFUNC_ERROR;
}
if(outs->alloc_filename)
tool_safefree(outs->filename);
curlx_safefree(outs->filename);
if(per->config->output_dir) {
char *f = curl_maprintf("%s/%s", per->config->output_dir,

View file

@ -61,57 +61,57 @@ static void free_config_fields(struct OperationConfig *config)
{
struct getout *urlnode;
tool_safefree(config->useragent);
tool_safefree(config->altsvc);
tool_safefree(config->hsts);
tool_safefree(config->haproxy_clientip);
curlx_safefree(config->useragent);
curlx_safefree(config->altsvc);
curlx_safefree(config->hsts);
curlx_safefree(config->haproxy_clientip);
curl_slist_free_all(config->cookies);
tool_safefree(config->cookiejar);
curlx_safefree(config->cookiejar);
curl_slist_free_all(config->cookiefiles);
curlx_dyn_free(&config->postdata);
tool_safefree(config->query);
tool_safefree(config->referer);
curlx_safefree(config->query);
curlx_safefree(config->referer);
tool_safefree(config->headerfile);
tool_safefree(config->ftpport);
tool_safefree(config->iface);
curlx_safefree(config->headerfile);
curlx_safefree(config->ftpport);
curlx_safefree(config->iface);
tool_safefree(config->range);
curlx_safefree(config->range);
tool_safefree(config->userpwd);
tool_safefree(config->tls_username);
tool_safefree(config->tls_password);
tool_safefree(config->tls_authtype);
tool_safefree(config->proxy_tls_username);
tool_safefree(config->proxy_tls_password);
tool_safefree(config->proxy_tls_authtype);
tool_safefree(config->proxyuserpwd);
tool_safefree(config->proxy);
curlx_safefree(config->userpwd);
curlx_safefree(config->tls_username);
curlx_safefree(config->tls_password);
curlx_safefree(config->tls_authtype);
curlx_safefree(config->proxy_tls_username);
curlx_safefree(config->proxy_tls_password);
curlx_safefree(config->proxy_tls_authtype);
curlx_safefree(config->proxyuserpwd);
curlx_safefree(config->proxy);
tool_safefree(config->dns_ipv6_addr);
tool_safefree(config->dns_ipv4_addr);
tool_safefree(config->dns_interface);
tool_safefree(config->dns_servers);
curlx_safefree(config->dns_ipv6_addr);
curlx_safefree(config->dns_ipv4_addr);
curlx_safefree(config->dns_interface);
curlx_safefree(config->dns_servers);
tool_safefree(config->noproxy);
curlx_safefree(config->noproxy);
tool_safefree(config->mail_from);
curlx_safefree(config->mail_from);
curl_slist_free_all(config->mail_rcpt);
tool_safefree(config->mail_auth);
curlx_safefree(config->mail_auth);
tool_safefree(config->netrc_file);
tool_safefree(config->output_dir);
tool_safefree(config->proto_str);
tool_safefree(config->proto_redir_str);
curlx_safefree(config->netrc_file);
curlx_safefree(config->output_dir);
curlx_safefree(config->proto_str);
curlx_safefree(config->proto_redir_str);
urlnode = config->url_list;
while(urlnode) {
struct getout *next = urlnode->next;
tool_safefree(urlnode->url);
tool_safefree(urlnode->outfile);
tool_safefree(urlnode->infile);
tool_safefree(urlnode);
curlx_safefree(urlnode->url);
curlx_safefree(urlnode->outfile);
curlx_safefree(urlnode->infile);
curlx_safefree(urlnode);
urlnode = next;
}
config->url_list = NULL;
@ -120,48 +120,48 @@ static void free_config_fields(struct OperationConfig *config)
config->url_out = NULL;
#ifndef CURL_DISABLE_IPFS
tool_safefree(config->ipfs_gateway);
curlx_safefree(config->ipfs_gateway);
#endif
tool_safefree(config->doh_url);
tool_safefree(config->cipher_list);
tool_safefree(config->proxy_cipher_list);
tool_safefree(config->cipher13_list);
tool_safefree(config->proxy_cipher13_list);
tool_safefree(config->cert);
tool_safefree(config->proxy_cert);
tool_safefree(config->cert_type);
tool_safefree(config->proxy_cert_type);
tool_safefree(config->cacert);
tool_safefree(config->login_options);
tool_safefree(config->proxy_cacert);
tool_safefree(config->capath);
tool_safefree(config->proxy_capath);
tool_safefree(config->crlfile);
tool_safefree(config->pinnedpubkey);
tool_safefree(config->proxy_pinnedpubkey);
tool_safefree(config->proxy_crlfile);
tool_safefree(config->key);
tool_safefree(config->proxy_key);
tool_safefree(config->key_type);
tool_safefree(config->proxy_key_type);
tool_safefree(config->key_passwd);
tool_safefree(config->proxy_key_passwd);
tool_safefree(config->pubkey);
tool_safefree(config->hostpubmd5);
tool_safefree(config->hostpubsha256);
tool_safefree(config->engine);
tool_safefree(config->etag_save_file);
tool_safefree(config->etag_compare_file);
tool_safefree(config->ssl_ec_curves);
tool_safefree(config->ssl_signature_algorithms);
tool_safefree(config->request_target);
tool_safefree(config->customrequest);
tool_safefree(config->krblevel);
tool_safefree(config->oauth_bearer);
tool_safefree(config->sasl_authzid);
tool_safefree(config->unix_socket_path);
tool_safefree(config->writeout);
tool_safefree(config->proto_default);
curlx_safefree(config->doh_url);
curlx_safefree(config->cipher_list);
curlx_safefree(config->proxy_cipher_list);
curlx_safefree(config->cipher13_list);
curlx_safefree(config->proxy_cipher13_list);
curlx_safefree(config->cert);
curlx_safefree(config->proxy_cert);
curlx_safefree(config->cert_type);
curlx_safefree(config->proxy_cert_type);
curlx_safefree(config->cacert);
curlx_safefree(config->login_options);
curlx_safefree(config->proxy_cacert);
curlx_safefree(config->capath);
curlx_safefree(config->proxy_capath);
curlx_safefree(config->crlfile);
curlx_safefree(config->pinnedpubkey);
curlx_safefree(config->proxy_pinnedpubkey);
curlx_safefree(config->proxy_crlfile);
curlx_safefree(config->key);
curlx_safefree(config->proxy_key);
curlx_safefree(config->key_type);
curlx_safefree(config->proxy_key_type);
curlx_safefree(config->key_passwd);
curlx_safefree(config->proxy_key_passwd);
curlx_safefree(config->pubkey);
curlx_safefree(config->hostpubmd5);
curlx_safefree(config->hostpubsha256);
curlx_safefree(config->engine);
curlx_safefree(config->etag_save_file);
curlx_safefree(config->etag_compare_file);
curlx_safefree(config->ssl_ec_curves);
curlx_safefree(config->ssl_signature_algorithms);
curlx_safefree(config->request_target);
curlx_safefree(config->customrequest);
curlx_safefree(config->krblevel);
curlx_safefree(config->oauth_bearer);
curlx_safefree(config->sasl_authzid);
curlx_safefree(config->unix_socket_path);
curlx_safefree(config->writeout);
curlx_safefree(config->proto_default);
curl_slist_free_all(config->quote);
curl_slist_free_all(config->postquote);
@ -180,16 +180,16 @@ static void free_config_fields(struct OperationConfig *config)
curl_slist_free_all(config->resolve);
curl_slist_free_all(config->connect_to);
tool_safefree(config->preproxy);
tool_safefree(config->proxy_service_name);
tool_safefree(config->service_name);
tool_safefree(config->ftp_account);
tool_safefree(config->ftp_alternative_to_user);
tool_safefree(config->aws_sigv4);
tool_safefree(config->ech);
tool_safefree(config->ech_config);
tool_safefree(config->ech_public);
tool_safefree(config->knownhosts);
curlx_safefree(config->preproxy);
curlx_safefree(config->proxy_service_name);
curlx_safefree(config->service_name);
curlx_safefree(config->ftp_account);
curlx_safefree(config->ftp_alternative_to_user);
curlx_safefree(config->aws_sigv4);
curlx_safefree(config->ech);
curlx_safefree(config->ech_config);
curlx_safefree(config->ech_public);
curlx_safefree(config->knownhosts);
}
void config_free(struct OperationConfig *config)
@ -355,14 +355,14 @@ CURLcode globalconf_init(void)
static void free_globalconfig(void)
{
tool_safefree(global->trace_dump);
curlx_safefree(global->trace_dump);
if(global->trace_fopened && global->trace_stream)
curlx_fclose(global->trace_stream);
global->trace_stream = NULL;
tool_safefree(global->ssl_sessions);
tool_safefree(global->libcurl);
curlx_safefree(global->ssl_sessions);
curlx_safefree(global->libcurl);
#ifdef _WIN32
curlx_free(global->term.buf);
#endif

View file

@ -33,12 +33,6 @@
#define checkprefix(a, b) curl_strnequal(b, STRCONST(a))
#define tool_safefree(ptr) \
do { \
curlx_free(ptr); \
(ptr) = NULL; \
} while(0)
extern struct GlobalConfig *global;
struct State {

View file

@ -160,7 +160,7 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
}
m = tool_mime_new(parent, TOOLMIME_STDIN);
if(!m)
tool_safefree(data);
curlx_safefree(data);
else {
m->data = data;
m->origin = origin;
@ -181,11 +181,11 @@ void tool_mime_free(struct tool_mime *mime)
tool_mime_free(mime->subparts);
if(mime->prev)
tool_mime_free(mime->prev);
tool_safefree(mime->name);
tool_safefree(mime->filename);
tool_safefree(mime->type);
tool_safefree(mime->encoder);
tool_safefree(mime->data);
curlx_safefree(mime->name);
curlx_safefree(mime->filename);
curlx_safefree(mime->type);
curlx_safefree(mime->encoder);
curlx_safefree(mime->data);
curl_slist_free_all(mime->headers);
curlx_free(mime);
}
@ -817,7 +817,7 @@ int formparse(const char *input,
warnf("error while reading standard input");
goto fail;
}
tool_safefree(part->data);
curlx_safefree(part->data);
part->size = -1;
result = CURLE_OK;
}
@ -850,7 +850,7 @@ int formparse(const char *input,
warnf("error while reading standard input");
goto fail;
}
tool_safefree(part->data);
curlx_safefree(part->data);
part->size = -1;
result = CURLE_OK;
}
@ -891,7 +891,7 @@ int formparse(const char *input,
}
err = 0;
fail:
tool_safefree(contents);
curlx_safefree(contents);
curl_slist_free_all(headers);
return err;
}

View file

@ -479,7 +479,7 @@ UNITTEST ParameterError parse_cert_parameter(const char *cert_parameter,
}
done:
if(err) {
tool_safefree(*certname);
curlx_safefree(*certname);
}
else
*certname_place = '\0';
@ -709,7 +709,7 @@ static ParameterError data_urlencode(const char *nextarg,
}
else {
char *enc = curl_easy_escape(NULL, postdata, (int)size);
tool_safefree(postdata); /* no matter if it worked or not */
curlx_safefree(postdata); /* no matter if it worked or not */
if(enc) {
char *n;
replace_url_encoded_space_by_plus(enc);
@ -1005,7 +1005,7 @@ static ParameterError set_data(cmdline_t cmd,
if(!err && curlx_dyn_addn(&config->postdata, postdata, size))
err = PARAM_NO_MEM;
tool_safefree(postdata);
curlx_safefree(postdata);
config->postfields = curlx_dyn_ptr(&config->postdata);
return err;
@ -1600,7 +1600,7 @@ static ParameterError parse_writeout(struct OperationConfig *config,
return PARAM_READ_ERROR;
}
}
tool_safefree(config->writeout);
curlx_safefree(config->writeout);
err = file2string(&config->writeout, file);
if(file && (file != stdin))
curlx_fclose(file);
@ -1759,7 +1759,7 @@ static ParameterError opt_none(struct OperationConfig *config,
case C_DUMP_CA_EMBED: /* --dump-ca-embed */
return PARAM_CA_EMBED_REQUESTED;
case C_FTP_PASV: /* --ftp-pasv */
tool_safefree(config->ftpport);
curlx_safefree(config->ftpport);
break;
case C_HTTP1_0: /* --http1.0 */
@ -2390,7 +2390,7 @@ static ParameterError opt_string(struct OperationConfig *config,
err = getstr(&config->doh_url, nextarg, ALLOW_BLANK);
if(!err && config->doh_url && !config->doh_url[0])
/* if given a blank string, make it NULL again */
tool_safefree(config->doh_url);
curlx_safefree(config->doh_url);
break;
case C_CIPHERS: /* -- ciphers */
@ -2664,7 +2664,7 @@ static ParameterError opt_string(struct OperationConfig *config,
if(len)
err = getstrn(&config->referer, nextarg, len, ALLOW_BLANK);
else
tool_safefree(config->referer);
curlx_safefree(config->referer);
}
break;
case C_CERT_TYPE: /* --cert-type */

View file

@ -195,7 +195,7 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url,
goto clean;
/* Free whatever it has now, rewriting is next */
tool_safefree(*url);
curlx_safefree(*url);
if(curl_url_get(uh, CURLUPART_URL, &cloneurl, CURLU_URLENCODE)) {
goto clean;

View file

@ -325,7 +325,7 @@ void single_transfer_cleanup(void)
struct State *state = &global->state;
/* Free list of remaining URLs */
glob_cleanup(&state->urlglob);
tool_safefree(state->uploadfile);
curlx_safefree(state->uploadfile);
/* Free list of globbed upload files */
glob_cleanup(&state->inglob);
}
@ -769,16 +769,16 @@ static CURLcode post_per_transfer(struct per_transfer *per,
curlx_fclose(per->heads.stream);
if(per->heads.alloc_filename)
tool_safefree(per->heads.filename);
curlx_safefree(per->heads.filename);
if(per->etag_save.fopened && per->etag_save.stream)
curlx_fclose(per->etag_save.stream);
if(per->etag_save.alloc_filename)
tool_safefree(per->etag_save.filename);
curlx_safefree(per->etag_save.filename);
if(outs->alloc_filename)
tool_safefree(outs->filename);
curlx_safefree(outs->filename);
curl_slist_free_all(per->hdrcbdata.headlist);
per->hdrcbdata.headlist = NULL;
return result;
@ -882,7 +882,7 @@ static CURLcode etag_compare(struct OperationConfig *config)
if((PARAM_OK == file2string(&etag_from_file, file)) &&
etag_from_file) {
char *h = curl_maprintf("If-None-Match: %s", etag_from_file);
tool_safefree(etag_from_file);
curlx_safefree(etag_from_file);
if(h) {
/* move it to the right memory */
header = curlx_strdup(h);
@ -1030,7 +1030,7 @@ static CURLcode setup_outfile(struct OperationConfig *config,
SANITIZEcode sc;
CURLcode result =
glob_match_url(&per->outfile, storefile, &state->urlglob, &sc);
tool_safefree(storefile);
curlx_safefree(storefile);
if(sc) {
if(sc == SANITIZE_ERR_OUT_OF_MEMORY)
return CURLE_OUT_OF_MEMORY;
@ -1052,7 +1052,7 @@ static CURLcode setup_outfile(struct OperationConfig *config,
if(config->output_dir && *config->output_dir) {
char *d = curl_maprintf("%s/%s", config->output_dir, per->outfile);
tool_safefree(per->outfile);
curlx_safefree(per->outfile);
if(d) {
per->outfile = curlx_strdup(d); /* move to right memory */
curl_free(d);
@ -1233,7 +1233,7 @@ static CURLcode create_single(struct OperationConfig *config,
if(state->upidx >= state->upnum) {
state->urlnum = 0;
tool_safefree(state->uploadfile);
curlx_safefree(state->uploadfile);
glob_cleanup(&state->inglob);
state->upidx = 0;
state->urlnode = u->next; /* next node */
@ -1286,7 +1286,7 @@ static CURLcode create_single(struct OperationConfig *config,
per->uploadfile = curlx_strdup(state->uploadfile);
if(!per->uploadfile ||
SetHTTPrequest(TOOL_HTTPREQ_PUT, &config->httpreq)) {
tool_safefree(per->uploadfile);
curlx_safefree(per->uploadfile);
curl_easy_cleanup(curl);
return CURLE_FAILED_INIT;
}
@ -1404,7 +1404,7 @@ static CURLcode create_single(struct OperationConfig *config,
state->urlidx = state->urlnum = 0;
glob_cleanup(&state->urlglob);
state->upidx++;
tool_safefree(state->uploadfile); /* clear it to get the next */
curlx_safefree(state->uploadfile); /* clear it to get the next */
}
*added = TRUE;
break;
@ -2155,7 +2155,7 @@ static CURLcode cacertpaths(struct OperationConfig *config)
#endif
return CURLE_OK;
fail:
Curl_safefree(config->capath);
curlx_safefree(config->capath);
return result;
}

View file

@ -37,10 +37,10 @@ void clean_getout(struct OperationConfig *config)
while(node) {
next = node->next;
tool_safefree(node->url);
tool_safefree(node->outfile);
tool_safefree(node->infile);
tool_safefree(node);
curlx_safefree(node->url);
curlx_safefree(node->outfile);
curlx_safefree(node->infile);
curlx_safefree(node);
node = next;
}
config->url_list = NULL;
@ -230,7 +230,7 @@ CURLcode get_url_file_name(char **filename, const char *url, SANITIZEcode *sc)
{
char *sanitized;
*sc = sanitize_file_name(&sanitized, *filename, 0);
tool_safefree(*filename);
curlx_safefree(*filename);
if(*sc)
return CURLE_BAD_FUNCTION_ARGUMENT;
*filename = sanitized;

View file

@ -79,8 +79,8 @@ CURLcode tool_ssls_load(struct OperationConfig *config,
i = imported = 0;
while(my_get_line(fp, &buf, &error)) {
++i;
tool_safefree(shmac);
tool_safefree(sdata);
curlx_safefree(shmac);
curlx_safefree(sdata);
line = curlx_dyn_ptr(&buf);
c = memchr(line, ':', strlen(line));
@ -165,7 +165,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr,
goto out;
if(EOF == fputc(':', ctx->fp))
goto out;
tool_safefree(enc);
curlx_safefree(enc);
result = curlx_base64_encode(sdata, sdata_len, &enc, &enc_len);
if(result)
goto out;

View file

@ -50,7 +50,7 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len)
pat->c.set.elem[0] = curlx_memdup0(fixed, len);
if(!pat->c.set.elem[0]) {
tool_safefree(pat->c.set.elem);
curlx_safefree(pat->c.set.elem);
return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
}
@ -204,7 +204,7 @@ error:
{
size_t i;
for(i = 0; i < size; i++)
tool_safefree(elem[i]);
curlx_safefree(elem[i]);
}
curlx_free(elem);
return result;
@ -542,11 +542,11 @@ void glob_cleanup(struct URLGlob *glob)
(glob->pattern[i].c.set.elem)) {
curl_off_t elem;
for(elem = 0; elem < glob->pattern[i].c.set.size; elem++)
tool_safefree(glob->pattern[i].c.set.elem[elem]);
tool_safefree(glob->pattern[i].c.set.elem);
curlx_safefree(glob->pattern[i].c.set.elem[elem]);
curlx_safefree(glob->pattern[i].c.set.elem);
}
}
tool_safefree(glob->pattern);
curlx_safefree(glob->pattern);
glob->palloc = 0;
curlx_dyn_free(&glob->buf);
}