From 57218d5327ad5de931580b528e4ba4e7a48f7359 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 10 Mar 2025 00:31:20 +0100 Subject: [PATCH] tidy-up: replace `Curl_safefree` with `free` before re-assignment Also drop `NULL` assignments after `Curl_safefree()`. Closes #16640 --- lib/cfilters.c | 2 +- lib/file.c | 2 +- lib/ftp.c | 12 ++++++------ lib/http.c | 8 ++++---- lib/http_aws_sigv4.c | 2 +- lib/http_negotiate.c | 4 ++-- lib/imap.c | 2 +- lib/rtsp.c | 7 +++---- lib/transfer.c | 2 +- lib/url.c | 25 ++++++++++++------------- lib/vssh/libssh2.c | 6 +++--- src/tool_formparse.c | 2 -- src/tool_getparam.c | 6 +++--- src/tool_operate.c | 2 +- src/tool_setopt.c | 12 ++++++------ 15 files changed, 45 insertions(+), 49 deletions(-) diff --git a/lib/cfilters.c b/lib/cfilters.c index 3521ed6ed2..4062b0dec4 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -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" diff --git a/lib/file.c b/lib/file.c index b493a13375..05741f47ac 100644 --- a/lib/file.c +++ b/lib/file.c @@ -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; diff --git a/lib/ftp.c b/lib/ftp.c index 1dbc56ef69..722dce41a3 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -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 { diff --git a/lib/http.c b/lib/http.c index 5a5636c017..69aef62ea6 100644 --- a/lib/http.c +++ b/lib/http.c @@ -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; diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index 712a726af8..eb1e2695d6 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -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; diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c index dd90a4e137..b1bac5f724 100644 --- a/lib/http_negotiate.c +++ b/lib/http_negotiate.c @@ -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; } diff --git a/lib/imap.c b/lib/imap.c index c05ff1e140..6091b76cc0 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -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); } } diff --git a/lib/rtsp.c b/lib/rtsp.c index 5ce8b001b2..c262896839 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -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; } diff --git a/lib/transfer.c b/lib/transfer.c index a6ee0a10fd..754bc2cda9 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -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) diff --git a/lib/url.c b/lib/url.c index e6bd969c45..7fd38683fb 100644 --- a/lib/url.c +++ b/lib/url.c @@ -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; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 06a6d94b59..71b854b4e5 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -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(""); diff --git a/src/tool_formparse.c b/src/tool_formparse.c index 5e680cc52b..06e9a38bb2 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -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; } diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 8d438bcbb9..33a859ec6e 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -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; diff --git a/src/tool_operate.c b/src/tool_operate.c index 453146097b..20b02df0d8 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -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! */ } } diff --git a/src/tool_setopt.c b/src/tool_setopt.c index 02bb47fcd4..390a86b525 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -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); -- 2.47.3