]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tidy-up: use `curlx_safefree()`
authorViktor Szakats <commit@vsz.me>
Wed, 20 May 2026 18:43:59 +0000 (20:43 +0200)
committerViktor Szakats <commit@vsz.me>
Wed, 20 May 2026 23:31:03 +0000 (01:31 +0200)
Closes #21700

19 files changed:
lib/cf-socket.c
lib/curl_gssapi.c
lib/ftp.c
lib/ftplistparser.c
lib/getinfo.c
lib/http.c
lib/multi.c
lib/url.c
lib/vauth/krb5_sspi.c
lib/vauth/ntlm_sspi.c
lib/vauth/spnego_sspi.c
lib/vtls/apple.c
lib/vtls/vtls.c
src/tool_getparam.c
tests/libtest/lib518.c
tests/libtest/lib537.c
tests/libtest/lib678.c
tests/unit/unit1607.c
tests/unit/unit1609.c

index 0edd0efe746b225d517dd51ee8c403e0962c821e..83534d7bdf2c74bef9410eb1ca10710ad012d848 100644 (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;
index 650d1908d0f3b9f1500cf74169c76e3c8811e0d4..af63d3a2c0d3d4daad9cf7da826d388db3eec890 100644 (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;
index 68c1a46ca5dca99a31300a0262d0f0d8e9ae0f87..836bc96e8998e2058293a03f645594a60ccf92f0 100644 (file)
--- 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;
index b5d9338c1bc29e0e8996211fcf72cb35acdae5cf..0c8cea4dc90b53599ec7bf6c92f8ba32e7fa9ee4 100644 (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;
index fab63e669a461e7c90b0bef7b2aca8de710b51bc..fde4aa4ef2d35f2233f45351eb4cc6eab8554b78 100644 (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;
index 9cb8b17b347cfd02defbc0e2705958566d37593d..5d98aab9d7c385243f881cab72a6ca99e75271b0 100644 (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;
 }
 
index 202a30b8a19771b73c3ac7b5c6b76057b89d2a5d..216a264a5215fffcb5319139d0ae11d364b00871 100644 (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;
   }
 
index 57b06390216804bed18b59f232c8fcbdac8e4d35..354505ad6c95c8454cb56fc0ca8084d201095193 100644 (file)
--- 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 */
   }
 
   /***********************************************************************
index b41d0bcbada544b58dca4d35aea85d06ed1ded8f..de1dc585391ce28b801c30e06a6f2699884f505f 100644 (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 */
index 06e3ec5ddfdfb10b1a673d04c11d78385d1a0c5a..67cf50faf8a43a141b8bde30951acc9f3af26225 100644 (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 */
index 8ba2316d880b5dd806bac0786e2b1392da833fb8..b7d82c04ddfb18d8659ef1a973681ed9ab308a54 100644 (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 */
index 5bd800b8cb84091263af22242b7bfd98a45c3db1..f9ffa2f5c2d8e8c64c7ff7d5cecfda7a1bea66e0 100644 (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,
index 73dd3f56f1db04508d75e77cfabcc0f216f6b909..e7dbad09c618cfcf56ac65f7daa1c788f56635ae 100644 (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;
   }
 }
index 6c69acd95bf357a8972d8d71c85745a14b954716..a7458a3b5fcf3dc756a77909a0c07f1c83c5c95e 100644 (file)
 
 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;
index e2c98db22de6f42c6abe4a07327c9912f5037cb7..c961ca3347d87c0dd56e9b69086be0f753ba5621 100644 (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;
     }
index 9257eaf02ea77e450971c6cf8e80a8eef56d303d..16e2f1b333e3fcf8cc666dd79a850e3836751e1c 100644 (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;
   }
index 7486505f76848f022d5adc5848c2aabc28242cc8..90295f42a8d6dd314408e04788243ed78cf31998 100644 (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;
       }
     }
   }
index dc12b99a568454d98da7e29e70c1a89fb39be83e..1380f9547e973890d8ca0ad5129751e2927d0b7b 100644 (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;
 
index 9d1691863962a5c3e1a9d582bf9bbdfcb3415f33..337fd7664dd3de590c524ff520f11a6cd2903125 100644 (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;