tidy-up: replace Curl_safefree with free before re-assignment

Also drop `NULL` assignments after `Curl_safefree()`.

Closes #16640
This commit is contained in:
Viktor Szakats 2025-03-10 00:31:20 +01:00
parent 9b523773b8
commit 57218d5327
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
15 changed files with 45 additions and 49 deletions

View file

@ -28,7 +28,7 @@
#include "strerror.h"
#include "cfilters.h"
#include "connect.h"
#include "url.h" /* for Curl_safefree() */
#include "url.h"
#include "sendf.h"
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
#include "multiif.h"

View file

@ -240,7 +240,7 @@ static CURLcode file_connect(struct Curl_easy *data, bool *done)
file->path = real_path;
#endif
#endif
Curl_safefree(file->freepath);
free(file->freepath);
file->freepath = real_path; /* free this when done */
file->fd = fd;

View file

@ -1907,7 +1907,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data,
/* postponed address resolution in case of tcp fastopen */
if(conn->bits.tcp_fastopen && !conn->bits.reuse && !ftpc->newhost[0]) {
Curl_safefree(ftpc->newhost);
free(ftpc->newhost);
ftpc->newhost = strdup(control_address(conn));
if(!ftpc->newhost)
return CURLE_OUT_OF_MEMORY;
@ -1952,7 +1952,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data,
Curl_resolv_unlink(data, &addr); /* we are done using this address */
Curl_safefree(conn->secondaryhostname);
free(conn->secondaryhostname);
conn->secondary_port = ftpc->newport;
conn->secondaryhostname = strdup(ftpc->newhost);
if(!conn->secondaryhostname)
@ -2902,7 +2902,7 @@ static CURLcode ftp_statemachine(struct Curl_easy *data,
free(dir);
return result;
}
Curl_safefree(ftpc->entrypath);
free(ftpc->entrypath);
ftpc->entrypath = dir; /* remember this */
infof(data, "Entry path is '%s'", ftpc->entrypath);
/* also save it where getinfo can access it: */
@ -2911,7 +2911,7 @@ static CURLcode ftp_statemachine(struct Curl_easy *data,
break;
}
Curl_safefree(ftpc->entrypath);
free(ftpc->entrypath);
ftpc->entrypath = dir; /* remember this */
infof(data, "Entry path is '%s'", ftpc->entrypath);
/* also save it where getinfo can access it: */
@ -2954,14 +2954,14 @@ static CURLcode ftp_statemachine(struct Curl_easy *data,
return result;
}
/* remember target server OS */
Curl_safefree(ftpc->server_os);
free(ftpc->server_os);
ftpc->server_os = os;
ftp_state(data, FTP_NAMEFMT);
break;
}
/* Nothing special for the target server. */
/* remember target server OS */
Curl_safefree(ftpc->server_os);
free(ftpc->server_os);
ftpc->server_os = os;
}
else {

View file

@ -582,7 +582,7 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data)
/* In case this is GSS auth, the newurl field is already allocated so
we must make sure to free it before allocating a new one. As figured
out in bug #2284386 */
Curl_safefree(data->req.newurl);
free(data->req.newurl);
data->req.newurl = strdup(data->state.url); /* clone URL */
if(!data->req.newurl)
return CURLE_OUT_OF_MEMORY;
@ -1910,7 +1910,7 @@ static CURLcode http_host(struct Curl_easy *data, struct connectdata *conn)
if(colon)
*colon = 0; /* The host must not include an embedded port number */
}
Curl_safefree(aptr->cookiehost);
free(aptr->cookiehost);
aptr->cookiehost = cookiehost;
}
#endif
@ -2735,7 +2735,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
if(!Curl_checkheaders(data, STRCONST("Accept-Encoding")) &&
data->set.str[STRING_ENCODING]) {
Curl_safefree(data->state.aptr.accept_encoding);
free(data->state.aptr.accept_encoding);
data->state.aptr.accept_encoding =
aprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]);
if(!data->state.aptr.accept_encoding)
@ -3070,7 +3070,7 @@ static CURLcode http_header(struct Curl_easy *data,
/* ignore empty data */
free(contenttype);
else {
Curl_safefree(data->info.contenttype);
free(data->info.contenttype);
data->info.contenttype = contenttype;
}
return CURLE_OK;

View file

@ -845,7 +845,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data)
Curl_strntoupper(&auth_headers[sizeof("Authorization: ") - 1],
Curl_str(&provider0), Curl_strlen(&provider0));
Curl_safefree(data->state.aptr.userpwd);
free(data->state.aptr.userpwd);
data->state.aptr.userpwd = auth_headers;
data->state.authhost.done = TRUE;
result = CURLE_OK;

View file

@ -203,12 +203,12 @@ CURLcode Curl_output_negotiate(struct Curl_easy *data,
if(proxy) {
#ifndef CURL_DISABLE_PROXY
Curl_safefree(data->state.aptr.proxyuserpwd);
free(data->state.aptr.proxyuserpwd);
data->state.aptr.proxyuserpwd = userp;
#endif
}
else {
Curl_safefree(data->state.aptr.userpwd);
free(data->state.aptr.userpwd);
data->state.aptr.userpwd = userp;
}

View file

@ -1134,7 +1134,7 @@ static CURLcode imap_state_select_resp(struct Curl_easy *data, int imapcode,
Curl_dyn_init(&uid, 20);
if(Curl_dyn_addn(&uid, p, len))
return CURLE_OUT_OF_MEMORY;
Curl_safefree(imapc->mailbox_uidvalidity);
free(imapc->mailbox_uidvalidity);
imapc->mailbox_uidvalidity = Curl_dyn_ptr(&uid);
}
}

View file

@ -346,8 +346,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
if(rtspreq == RTSPREQ_SETUP && !p_transport) {
/* New Transport: setting? */
if(data->set.str[STRING_RTSP_TRANSPORT]) {
Curl_safefree(data->state.aptr.rtsp_transport);
free(data->state.aptr.rtsp_transport);
data->state.aptr.rtsp_transport =
aprintf("Transport: %s\r\n",
data->set.str[STRING_RTSP_TRANSPORT]);
@ -373,7 +372,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
/* Accept-Encoding header */
if(!Curl_checkheaders(data, STRCONST("Accept-Encoding")) &&
data->set.str[STRING_ENCODING]) {
Curl_safefree(data->state.aptr.accept_encoding);
free(data->state.aptr.accept_encoding);
data->state.aptr.accept_encoding =
aprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]);
@ -427,7 +426,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
/* Check to see if there is a range set in the custom headers */
if(!Curl_checkheaders(data, STRCONST("Range")) && data->state.range) {
Curl_safefree(data->state.aptr.rangeline);
free(data->state.aptr.rangeline);
data->state.aptr.rangeline = aprintf("Range: %s\r\n", data->state.range);
p_range = data->state.aptr.rangeline;
}

View file

@ -656,7 +656,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
* protocol.
*/
if(data->set.str[STRING_USERAGENT]) {
Curl_safefree(data->state.aptr.uagent);
free(data->state.aptr.uagent);
data->state.aptr.uagent =
aprintf("User-Agent: %s\r\n", data->set.str[STRING_USERAGENT]);
if(!data->state.aptr.uagent)

View file

@ -2261,7 +2261,7 @@ static CURLcode parse_proxy(struct Curl_easy *data,
goto error;
if(proxyuser || proxypasswd) {
Curl_safefree(proxyinfo->user);
free(proxyinfo->user);
proxyinfo->user = proxyuser;
result = Curl_setstropt(&data->state.aptr.proxyuser, proxyuser);
proxyuser = NULL;
@ -2333,7 +2333,7 @@ static CURLcode parse_proxy(struct Curl_easy *data,
result = CURLE_OUT_OF_MEMORY;
goto error;
}
Curl_safefree(proxyinfo->host.rawalloc);
free(proxyinfo->host.rawalloc);
proxyinfo->host.rawalloc = host;
proxyinfo->host.name = host;
host = NULL;
@ -2342,7 +2342,7 @@ static CURLcode parse_proxy(struct Curl_easy *data,
if(!is_unix_proxy) {
#endif
Curl_safefree(proxyinfo->host.rawalloc);
free(proxyinfo->host.rawalloc);
proxyinfo->host.rawalloc = host;
if(host[0] == '[') {
/* this is a numerical IPv6, strip off the brackets */
@ -2529,7 +2529,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data,
if(!conn->socks_proxy.user) {
conn->socks_proxy.user = conn->http_proxy.user;
conn->http_proxy.user = NULL;
Curl_safefree(conn->socks_proxy.passwd);
free(conn->socks_proxy.passwd);
conn->socks_proxy.passwd = conn->http_proxy.passwd;
conn->http_proxy.passwd = NULL;
}
@ -2764,7 +2764,7 @@ static CURLcode override_login(struct Curl_easy *data,
}
}
if(url_provided) {
Curl_safefree(conn->user);
free(conn->user);
conn->user = strdup(*userp);
if(!conn->user)
return CURLE_OUT_OF_MEMORY;
@ -3283,8 +3283,8 @@ static void reuse_conn(struct Curl_easy *data,
* be new for this request even when we reuse an existing connection */
if(temp->user) {
/* use the new username and password though */
Curl_safefree(existing->user);
Curl_safefree(existing->passwd);
free(existing->user);
free(existing->passwd);
existing->user = temp->user;
existing->passwd = temp->passwd;
temp->user = NULL;
@ -3295,10 +3295,10 @@ static void reuse_conn(struct Curl_easy *data,
existing->bits.proxy_user_passwd = temp->bits.proxy_user_passwd;
if(existing->bits.proxy_user_passwd) {
/* use the new proxy username and proxy password though */
Curl_safefree(existing->http_proxy.user);
Curl_safefree(existing->socks_proxy.user);
Curl_safefree(existing->http_proxy.passwd);
Curl_safefree(existing->socks_proxy.passwd);
free(existing->http_proxy.user);
free(existing->socks_proxy.user);
free(existing->http_proxy.passwd);
free(existing->socks_proxy.passwd);
existing->http_proxy.user = temp->http_proxy.user;
existing->socks_proxy.user = temp->socks_proxy.user;
existing->http_proxy.passwd = temp->http_proxy.passwd;
@ -3335,8 +3335,7 @@ static void reuse_conn(struct Curl_easy *data,
temp->conn_to_host.rawalloc = NULL;
existing->conn_to_port = temp->conn_to_port;
existing->remote_port = temp->remote_port;
Curl_safefree(existing->hostname_resolve);
free(existing->hostname_resolve);
existing->hostname_resolve = temp->hostname_resolve;
temp->hostname_resolve = NULL;

View file

@ -1262,7 +1262,7 @@ sftp_pkey_init(struct Curl_easy *data,
if(!sshc->rsa)
out_of_memory = TRUE;
else if(stat(sshc->rsa, &sbuf)) {
Curl_safefree(sshc->rsa);
free(sshc->rsa);
sshc->rsa = aprintf("%s/.ssh/id_dsa", home);
if(!sshc->rsa)
out_of_memory = TRUE;
@ -1276,10 +1276,10 @@ sftp_pkey_init(struct Curl_easy *data,
/* Nothing found; try the current dir. */
sshc->rsa = strdup("id_rsa");
if(sshc->rsa && stat(sshc->rsa, &sbuf)) {
Curl_safefree(sshc->rsa);
free(sshc->rsa);
sshc->rsa = strdup("id_dsa");
if(sshc->rsa && stat(sshc->rsa, &sbuf)) {
Curl_safefree(sshc->rsa);
free(sshc->rsa);
/* Out of guesses. Set to the empty string to avoid
* surprising info messages. */
sshc->rsa = strdup("");

View file

@ -839,7 +839,6 @@ int formparse(struct OperationConfig *config,
goto fail;
}
Curl_safefree(part->data);
part->data = NULL;
part->size = -1;
res = CURLE_OK;
}
@ -876,7 +875,6 @@ int formparse(struct OperationConfig *config,
goto fail;
}
Curl_safefree(part->data);
part->data = NULL;
part->size = -1;
res = CURLE_OK;
}

View file

@ -512,10 +512,10 @@ GetFileAndPassword(const char *nextarg, char **file, char **password)
char *certname, *passphrase;
if(nextarg) {
parse_cert_parameter(nextarg, &certname, &passphrase);
Curl_safefree(*file);
free(*file);
*file = certname;
if(passphrase) {
Curl_safefree(*password);
free(*password);
*password = passphrase;
}
}
@ -1503,7 +1503,7 @@ static ParameterError parse_verbose(struct GlobalConfig *global,
switch(global->verbosity) {
case 0:
global->verbosity = 1;
Curl_safefree(global->trace_dump);
free(global->trace_dump);
global->trace_dump = strdup("%");
if(!global->trace_dump)
err = PARAM_NO_MEM;

View file

@ -1783,7 +1783,7 @@ static CURLcode append2query(struct GlobalConfig *global,
if(uerr)
result = urlerr_cvt(uerr);
else {
Curl_safefree(per->url); /* free previous URL */
free(per->url); /* free previous URL */
per->url = updated; /* use our new URL instead! */
}
}

View file

@ -406,7 +406,7 @@ static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno)
CLEAN1("curl_slist_free_all(slist%d);", *slistno);
CLEAN1("slist%d = NULL;", *slistno);
for(; slist; slist = slist->next) {
Curl_safefree(escaped);
free(escaped);
escaped = c_escape(slist->data, ZERO_TERMINATED);
if(!escaped)
return CURLE_OUT_OF_MEMORY;
@ -458,7 +458,7 @@ static CURLcode libcurl_generate_mime_part(CURL *curl,
case TOOLMIME_DATA:
data = part->data;
if(!ret) {
Curl_safefree(escaped);
free(escaped);
escaped = c_escape(data, ZERO_TERMINATED);
NULL_CHECK(escaped);
CODE2("curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);",
@ -492,28 +492,28 @@ static CURLcode libcurl_generate_mime_part(CURL *curl,
}
if(!ret && part->encoder) {
Curl_safefree(escaped);
free(escaped);
escaped = c_escape(part->encoder, ZERO_TERMINATED);
NULL_CHECK(escaped);
CODE2("curl_mime_encoder(part%d, \"%s\");", mimeno, escaped);
}
if(!ret && filename) {
Curl_safefree(escaped);
free(escaped);
escaped = c_escape(filename, ZERO_TERMINATED);
NULL_CHECK(escaped);
CODE2("curl_mime_filename(part%d, \"%s\");", mimeno, escaped);
}
if(!ret && part->name) {
Curl_safefree(escaped);
free(escaped);
escaped = c_escape(part->name, ZERO_TERMINATED);
NULL_CHECK(escaped);
CODE2("curl_mime_name(part%d, \"%s\");", mimeno, escaped);
}
if(!ret && part->type) {
Curl_safefree(escaped);
free(escaped);
escaped = c_escape(part->type, ZERO_TERMINATED);
NULL_CHECK(escaped);
CODE2("curl_mime_type(part%d, \"%s\");", mimeno, escaped);