diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 0edd0efe74..83534d7bdf 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -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; diff --git a/lib/curl_gssapi.c b/lib/curl_gssapi.c index 650d1908d0..af63d3a2c0 100644 --- a/lib/curl_gssapi.c +++ b/lib/curl_gssapi.c @@ -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; diff --git a/lib/ftp.c b/lib/ftp.c index 68c1a46ca5..836bc96e89 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -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; diff --git a/lib/ftplistparser.c b/lib/ftplistparser.c index b5d9338c1b..0c8cea4dc9 100644 --- a/lib/ftplistparser.c +++ b/lib/ftplistparser.c @@ -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; diff --git a/lib/getinfo.c b/lib/getinfo.c index fab63e669a..fde4aa4ef2 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -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; diff --git a/lib/http.c b/lib/http.c index 9cb8b17b34..5d98aab9d7 100644 --- a/lib/http.c +++ b/lib/http.c @@ -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; } diff --git a/lib/multi.c b/lib/multi.c index 202a30b8a1..216a264a52 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -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; } diff --git a/lib/url.c b/lib/url.c index 57b0639021..354505ad6c 100644 --- a/lib/url.c +++ b/lib/url.c @@ -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 */ } /*********************************************************************** diff --git a/lib/vauth/krb5_sspi.c b/lib/vauth/krb5_sspi.c index b41d0bcbad..de1dc58539 100644 --- a/lib/vauth/krb5_sspi.c +++ b/lib/vauth/krb5_sspi.c @@ -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 */ diff --git a/lib/vauth/ntlm_sspi.c b/lib/vauth/ntlm_sspi.c index 06e3ec5ddf..67cf50faf8 100644 --- a/lib/vauth/ntlm_sspi.c +++ b/lib/vauth/ntlm_sspi.c @@ -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 */ diff --git a/lib/vauth/spnego_sspi.c b/lib/vauth/spnego_sspi.c index 8ba2316d88..b7d82c04dd 100644 --- a/lib/vauth/spnego_sspi.c +++ b/lib/vauth/spnego_sspi.c @@ -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 */ diff --git a/lib/vtls/apple.c b/lib/vtls/apple.c index 5bd800b8cb..f9ffa2f5c2 100644 --- a/lib/vtls/apple.c +++ b/lib/vtls/apple.c @@ -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, diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 73dd3f56f1..e7dbad09c6 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -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; } } diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 6c69acd95b..a7458a3b5f 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -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; diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c index e2c98db22d..c961ca3347 100644 --- a/tests/libtest/lib518.c +++ b/tests/libtest/lib518.c @@ -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; } diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c index 9257eaf02e..16e2f1b333 100644 --- a/tests/libtest/lib537.c +++ b/tests/libtest/lib537.c @@ -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; } diff --git a/tests/libtest/lib678.c b/tests/libtest/lib678.c index 7486505f76..90295f42a8 100644 --- a/tests/libtest/lib678.c +++ b/tests/libtest/lib678.c @@ -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; } } } diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c index dc12b99a56..1380f9547e 100644 --- a/tests/unit/unit1607.c +++ b/tests/unit/unit1607.c @@ -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; diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c index 9d16918639..337fd7664d 100644 --- a/tests/unit/unit1609.c +++ b/tests/unit/unit1609.c @@ -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;