tidy-up: use curlx_safefree()

Closes #21700
This commit is contained in:
Viktor Szakats 2026-05-20 20:43:59 +02:00
parent d3b04e5600
commit bcd0497c81
No known key found for this signature in database
19 changed files with 41 additions and 80 deletions

View file

@ -507,8 +507,7 @@ CURLcode Curl_parse_interface(const char *input,
++host_part;
*host = curlx_memdup0(host_part, len - (host_part - input));
if(!*host) {
curlx_free(*iface);
*iface = NULL;
curlx_safefree(*iface);
return CURLE_OUT_OF_MEMORY;
}
return CURLE_OK;

View file

@ -302,8 +302,7 @@ static OM_uint32 stub_gss_delete_sec_context(
return GSS_S_FAILURE;
}
curlx_free(*context);
*context = NULL;
curlx_safefree(*context);
*min = 0;
return GSS_S_COMPLETE;

View file

@ -3655,8 +3655,7 @@ static void ftp_done_path(struct Curl_easy *data, struct ftp_conn *ftpc,
* the error path) */
ftpc->ctl_valid = FALSE; /* mark control connection as bad */
connclose(conn, "FTP: out of memory!"); /* mark for connection closure */
curlx_free(ftpc->prevpath);
ftpc->prevpath = NULL; /* no path remembering */
curlx_safefree(ftpc->prevpath); /* no path remembering */
}
else { /* remember working directory for connection reuse */
const char *rawPath = ftpc->rawpath;

View file

@ -199,10 +199,8 @@ void Curl_wildcard_dtor(struct WildcardData **wcp)
DEBUGASSERT(wc->ftpwc == NULL);
Curl_llist_destroy(&wc->filelist, NULL);
curlx_free(wc->path);
wc->path = NULL;
curlx_free(wc->pattern);
wc->pattern = NULL;
curlx_safefree(wc->path);
curlx_safefree(wc->pattern);
wc->state = CURLWC_INIT;
curlx_free(wc);
*wcp = NULL;

View file

@ -67,11 +67,8 @@ void Curl_initinfo(struct Curl_easy *data)
info->httpauthpicked = 0;
info->numconnects = 0;
curlx_free(info->contenttype);
info->contenttype = NULL;
curlx_free(info->wouldredirect);
info->wouldredirect = NULL;
curlx_safefree(info->contenttype);
curlx_safefree(info->wouldredirect);
memset(&info->primary, 0, sizeof(info->primary));
info->retry_after = 0;

View file

@ -1976,10 +1976,8 @@ static CURLcode http_useragent(struct Curl_easy *data)
it might have been used in the proxy connect, but if we have got a header
with the user-agent string specified, we erase the previously made string
here. */
if(Curl_checkheaders(data, STRCONST("User-Agent"))) {
curlx_free(data->state.aptr.uagent);
data->state.aptr.uagent = NULL;
}
if(Curl_checkheaders(data, STRCONST("User-Agent")))
curlx_safefree(data->state.aptr.uagent);
return CURLE_OK;
}

View file

@ -3972,8 +3972,7 @@ CURLcode Curl_multi_xfer_buf_borrow(struct Curl_easy *data,
if(data->multi->xfer_buf &&
data->set.buffer_size > data->multi->xfer_buf_len) {
/* not large enough, get a new one */
curlx_free(data->multi->xfer_buf);
data->multi->xfer_buf = NULL;
curlx_safefree(data->multi->xfer_buf);
data->multi->xfer_buf_len = 0;
}
@ -4025,8 +4024,7 @@ CURLcode Curl_multi_xfer_ulbuf_borrow(struct Curl_easy *data,
if(data->multi->xfer_ulbuf &&
data->set.upload_buffer_size > data->multi->xfer_ulbuf_len) {
/* not large enough, get a new one */
curlx_free(data->multi->xfer_ulbuf);
data->multi->xfer_ulbuf = NULL;
curlx_safefree(data->multi->xfer_ulbuf);
data->multi->xfer_ulbuf_len = 0;
}
@ -4073,8 +4071,7 @@ CURLcode Curl_multi_xfer_sockbuf_borrow(struct Curl_easy *data,
if(data->multi->xfer_sockbuf && blen > data->multi->xfer_sockbuf_len) {
/* not large enough, get a new one */
curlx_free(data->multi->xfer_sockbuf);
data->multi->xfer_sockbuf = NULL;
curlx_safefree(data->multi->xfer_sockbuf);
data->multi->xfer_sockbuf_len = 0;
}

View file

@ -1954,16 +1954,14 @@ static CURLcode url_set_conn_proxies(struct Curl_easy *data,
curlx_safefree(no_proxy);
if(proxy && (!*proxy || (conn->scheme->flags & PROTOPT_NONETWORK))) {
curlx_free(proxy); /* Do not bother with an empty proxy string
or if the protocol does not work with network */
proxy = NULL;
curlx_safefree(proxy); /* Do not bother with an empty proxy string
or if the protocol does not work with network */
}
if(pre_proxy && (!*pre_proxy ||
(conn->scheme->flags & PROTOPT_NONETWORK))) {
curlx_free(pre_proxy); /* Do not bother with an empty socks proxy string
or if the protocol does not work with
network */
pre_proxy = NULL;
curlx_safefree(pre_proxy); /* Do not bother with an empty socks proxy
string or if the protocol does not work
with network */
}
/***********************************************************************

View file

@ -155,8 +155,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
krb5->p_identity, NULL, NULL,
krb5->credentials, NULL);
if(status != SEC_E_OK) {
curlx_free(krb5->credentials);
krb5->credentials = NULL;
curlx_safefree(krb5->credentials);
return CURLE_LOGIN_DENIED;
}
@ -433,15 +432,13 @@ void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5)
/* Free our security context */
if(krb5->context) {
Curl_pSecFn->DeleteSecurityContext(krb5->context);
curlx_free(krb5->context);
krb5->context = NULL;
curlx_safefree(krb5->context);
}
/* Free our credentials handle */
if(krb5->credentials) {
Curl_pSecFn->FreeCredentialsHandle(krb5->credentials);
curlx_free(krb5->credentials);
krb5->credentials = NULL;
curlx_safefree(krb5->credentials);
}
/* Free our identity */

View file

@ -140,8 +140,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
ntlm->p_identity, NULL, NULL,
ntlm->credentials, NULL);
if(status != SEC_E_OK) {
curlx_free(ntlm->credentials);
ntlm->credentials = NULL;
curlx_safefree(ntlm->credentials);
return CURLE_LOGIN_DENIED;
}
@ -328,15 +327,13 @@ void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm)
/* Free our security context */
if(ntlm->context) {
Curl_pSecFn->DeleteSecurityContext(ntlm->context);
curlx_free(ntlm->context);
ntlm->context = NULL;
curlx_safefree(ntlm->context);
}
/* Free our credentials handle */
if(ntlm->credentials) {
Curl_pSecFn->FreeCredentialsHandle(ntlm->credentials);
curlx_free(ntlm->credentials);
ntlm->credentials = NULL;
curlx_safefree(ntlm->credentials);
}
/* Free our identity */

View file

@ -160,8 +160,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
nego->p_identity, NULL, NULL,
nego->credentials, NULL);
if(nego->status != SEC_E_OK) {
curlx_free(nego->credentials);
nego->credentials = NULL;
curlx_safefree(nego->credentials);
return CURLE_AUTH_ERROR;
}
@ -323,15 +322,13 @@ void Curl_auth_cleanup_spnego(struct negotiatedata *nego)
/* Free our security context */
if(nego->context) {
Curl_pSecFn->DeleteSecurityContext(nego->context);
curlx_free(nego->context);
nego->context = NULL;
curlx_safefree(nego->context);
}
/* Free our credentials handle */
if(nego->credentials) {
Curl_pSecFn->FreeCredentialsHandle(nego->credentials);
curlx_free(nego->credentials);
nego->credentials = NULL;
curlx_safefree(nego->credentials);
}
/* Free our identity */

View file

@ -238,10 +238,8 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf,
err_desc = curlx_malloc(size + 1);
if(err_desc) {
if(!CFStringGetCString(error_ref, err_desc, size,
kCFStringEncodingUTF8)) {
curlx_free(err_desc);
err_desc = NULL;
}
kCFStringEncodingUTF8))
curlx_safefree(err_desc);
}
}
infof(data, "Apple SecTrust failure %ld%s%s", code,

View file

@ -632,8 +632,7 @@ void Curl_ssl_free_certinfo(struct Curl_easy *data)
ci->certinfo[i] = NULL;
}
curlx_free(ci->certinfo); /* free the actual array too */
ci->certinfo = NULL;
curlx_safefree(ci->certinfo); /* free the actual array too */
ci->num_of_certs = 0;
}
}

View file

@ -43,10 +43,8 @@
static ParameterError getstr(char **str, const char *val, bool allowblank)
{
if(*str) {
curlx_free(*str);
*str = NULL;
}
if(*str)
curlx_safefree(*str);
DEBUGASSERT(val);
if(!allowblank && !val[0])
return PARAM_BLANK_STRING;
@ -61,10 +59,8 @@ static ParameterError getstr(char **str, const char *val, bool allowblank)
static ParameterError getstrn(char **str, const char *val,
size_t len, bool allowblank)
{
if(*str) {
curlx_free(*str);
*str = NULL;
}
if(*str)
curlx_safefree(*str);
DEBUGASSERT(val);
if(!allowblank && !val[0])
return PARAM_BLANK_STRING;

View file

@ -60,8 +60,7 @@ static void t518_close_file_descriptors(void)
t518_num_open.rlim_cur++)
if(t518_testfd[t518_num_open.rlim_cur] > 0)
curlx_close(t518_testfd[t518_num_open.rlim_cur]);
curlx_free(t518_testfd);
t518_testfd = NULL;
curlx_safefree(t518_testfd);
}
static int t518_fopen_works(void)
@ -289,8 +288,7 @@ static int t518_test_rlimit(int keep_open)
curl_msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL);
t518_store_errmsg(strbuff, errno);
curl_mfprintf(stderr, "%s\n", t518_msgbuff);
curlx_free(t518_testfd);
t518_testfd = NULL;
curlx_safefree(t518_testfd);
curlx_free(memchunk);
return -8;
}
@ -330,8 +328,7 @@ static int t518_test_rlimit(int keep_open)
t518_testfd[t518_num_open.rlim_cur] >= 0;
t518_num_open.rlim_cur++)
curlx_close(t518_testfd[t518_num_open.rlim_cur]);
curlx_free(t518_testfd);
t518_testfd = NULL;
curlx_safefree(t518_testfd);
curlx_free(memchunk);
return -9;
}

View file

@ -57,8 +57,7 @@ static void t537_close_file_descriptors(void)
t537_num_open.rlim_cur++)
if(t537_testfd[t537_num_open.rlim_cur] > 0)
curlx_close(t537_testfd[t537_num_open.rlim_cur]);
curlx_free(t537_testfd);
t537_testfd = NULL;
curlx_safefree(t537_testfd);
}
static int t537_fopen_works(void)
@ -291,8 +290,7 @@ static int t537_test_rlimit(int keep_open)
curl_msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL);
t537_store_errmsg(strbuff, errno);
curl_mfprintf(stderr, "%s\n", t537_msgbuff);
curlx_free(t537_testfd);
t537_testfd = NULL;
curlx_safefree(t537_testfd);
curlx_free(memchunk);
return -7;
}

View file

@ -47,9 +47,8 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize)
continue_reading = FALSE;
curlx_fclose(fInCert);
if(!continue_reading) {
curlx_free(data);
curlx_safefree(data);
datasize = 0;
data = NULL;
}
}
}

View file

@ -132,8 +132,7 @@ static CURLcode test_unit1607(const char *arg)
goto error;
dns = Curl_hash_pick(&multi->dnscache.entries,
entry_id, strlen(entry_id) + 1);
curlx_free(entry_id);
entry_id = NULL;
curlx_safefree(entry_id);
addr = dns ? dns->addr : NULL;

View file

@ -134,8 +134,7 @@ static CURLcode test_unit1609(const char *arg)
dns = Curl_hash_pick(&multi->dnscache.entries,
entry_id, strlen(entry_id) + 1);
curlx_free(entry_id);
entry_id = NULL;
curlx_safefree(entry_id);
addr = dns ? dns->addr : NULL;