]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: tidy up and dedupe `strdup` functions
authorViktor Szakats <commit@vsz.me>
Mon, 2 Feb 2026 13:08:14 +0000 (14:08 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 3 Feb 2026 13:02:30 +0000 (14:02 +0100)
- de-dupe lib/src strdup/memdup functions into curlx.
- introduce `CURLX_STRDUP_LOW()` for mapping `strdup()`, and to do it at
  one place within the code, in `curl_setup.h`.
- tests/server: use `curlx_strdup()`. (Also to fix building without
  a system `strdup()`.)
- curlx/curlx.h: shorten and tidy up.
- adjust Windows build path to not need `HAVE_STRDUP`.
- build: stop detecting `HAVE_STRDUP` on Windows.

Closes #20497

50 files changed:
CMakeLists.txt
configure.ac
lib/Makefile.inc
lib/bufref.c
lib/cf-socket.c
lib/config-win32.h
lib/cookie.c
lib/curl_setup.h
lib/curl_sspi.c
lib/curlx/curlx.h
lib/curlx/dynbuf.c
lib/curlx/strdup.c [moved from lib/strdup.c with 86% similarity]
lib/curlx/strdup.h [moved from lib/strdup.h with 71% similarity]
lib/doh.c
lib/easy.c
lib/formdata.c
lib/ftp.c
lib/http.c
lib/http_aws_sigv4.c
lib/httpsrr.c
lib/mime.c
lib/pop3.c
lib/rtsp.c
lib/setopt.c
lib/socks_gssapi.c
lib/url.c
lib/urlapi.c
lib/vauth/digest_sspi.c
lib/vauth/ntlm.c
lib/vauth/ntlm_sspi.c
lib/vtls/gtls.c
lib/vtls/mbedtls.c
lib/vtls/openssl.c
lib/vtls/schannel.c
lib/vtls/vtls.c
lib/vtls/vtls_spack.c
lib/vtls/wolfssl.c
src/Makefile.inc
src/tool_cb_hdr.c
src/tool_getparam.c
src/tool_setup.h
src/tool_strdup.c [deleted file]
src/tool_strdup.h [deleted file]
src/tool_urlglob.c
src/var.c
tests/libtest/lib509.c
tests/libtest/memptr.c
tests/server/.checksrc
tests/server/first.h
tests/server/tftpd.c

index bd30a00f8e2b89eb4cd6fe08e88f736f15d42d4b..2b324e9585bcb1d2a6d18438eafa19a45214d53e 100644 (file)
@@ -1607,9 +1607,7 @@ check_function_exists("getrlimit"     HAVE_GETRLIMIT)
 check_function_exists("setlocale"     HAVE_SETLOCALE)
 check_function_exists("setrlimit"     HAVE_SETRLIMIT)
 
-if(WIN32)
-  set(HAVE_STRDUP 1)  # to not define local implementation. curl uses _strdup() on Windows.
-else()
+if(NOT WIN32)
   check_function_exists("if_nametoindex"  HAVE_IF_NAMETOINDEX)  # net/if.h
   check_function_exists("realpath"        HAVE_REALPATH)
   check_function_exists("sched_yield"     HAVE_SCHED_YIELD)
index 611399bfcfbc46779cd307916b676e277aac0f65..f400a02076147a355ad44dae435f24d2b49ca01b 100644 (file)
@@ -4160,7 +4160,6 @@ CURL_CHECK_FUNC_SIGNAL
 CURL_CHECK_FUNC_SIGSETJMP
 CURL_CHECK_FUNC_SOCKET
 CURL_CHECK_FUNC_SOCKETPAIR
-CURL_CHECK_FUNC_STRDUP
 CURL_CHECK_FUNC_STRERROR_R
 
 case $host in
@@ -4205,6 +4204,7 @@ if test "$curl_cv_native_windows" != "yes"; then
   CURL_CHECK_FUNC_INET_PTON
   CURL_CHECK_FUNC_STRCASECMP
   CURL_CHECK_FUNC_STRCMPI
+  CURL_CHECK_FUNC_STRDUP
   CURL_CHECK_FUNC_STRICMP
 fi
 
index 0146d875575b5d67864decfd9a7ef1fcd0c99dbe..e5f7457e4306f769ff639e7a19586b8a4f422aa5 100644 (file)
@@ -33,6 +33,7 @@ LIB_CURLX_CFILES =      \
   curlx/multibyte.c     \
   curlx/nonblock.c      \
   curlx/strcopy.c       \
+  curlx/strdup.c        \
   curlx/strerr.c        \
   curlx/strparse.c      \
   curlx/timediff.c      \
@@ -55,6 +56,7 @@ LIB_CURLX_HFILES =      \
   curlx/nonblock.h      \
   curlx/snprintf.h      \
   curlx/strcopy.h       \
+  curlx/strdup.h        \
   curlx/strerr.h        \
   curlx/strparse.h      \
   curlx/timediff.h      \
@@ -252,7 +254,6 @@ LIB_CFILES =         \
   socks_sspi.c       \
   splay.c            \
   strcase.c          \
-  strdup.c           \
   strequal.c         \
   strerror.c         \
   system_win32.c     \
@@ -382,7 +383,6 @@ LIB_HFILES =         \
   socks.h            \
   splay.h            \
   strcase.h          \
-  strdup.h           \
   strerror.h         \
   system_win32.h     \
   telnet.h           \
index b1272d589de21f0d80b4638427a1a4795ef7bf11..50fafdac03f9f1e09e9a278a1ca19a74dd557239 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "urldata.h"
 #include "bufref.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 
 #ifdef DEBUGBUILD
 #define SIGNATURE 0x5c48e9b2    /* Random pattern. */
@@ -128,7 +128,7 @@ CURLcode Curl_bufref_memdup0(struct bufref *br, const void *ptr, size_t len)
   DEBUGASSERT(len <= CURL_MAX_INPUT_LENGTH);
 
   if(ptr) {
-    cpy = Curl_memdup0(ptr, len);
+    cpy = curlx_memdup0(ptr, len);
     if(!cpy)
       return CURLE_OUT_OF_MEMORY;
   }
index 2f08ecfbb47a3f2cca78d01409f908861ccffbdd..2e4eba52454e670cbbb52b131af671900acc5ef8 100644 (file)
@@ -69,7 +69,7 @@
 #include "conncache.h"
 #include "multihandle.h"
 #include "rand.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "system_win32.h"
 #include "curlx/nonblock.h"
 #include "curlx/version_win32.h"
@@ -483,14 +483,14 @@ CURLcode Curl_parse_interface(const char *input,
     input += strlen(if_prefix);
     if(!*input)
       return CURLE_BAD_FUNCTION_ARGUMENT;
-    *iface = Curl_memdup0(input, len - strlen(if_prefix));
+    *iface = curlx_memdup0(input, len - strlen(if_prefix));
     return *iface ? CURLE_OK : CURLE_OUT_OF_MEMORY;
   }
   else if(!strncmp(host_prefix, input, strlen(host_prefix))) {
     input += strlen(host_prefix);
     if(!*input)
       return CURLE_BAD_FUNCTION_ARGUMENT;
-    *host = Curl_memdup0(input, len - strlen(host_prefix));
+    *host = curlx_memdup0(input, len - strlen(host_prefix));
     return *host ? CURLE_OK : CURLE_OUT_OF_MEMORY;
   }
   else if(!strncmp(if_host_prefix, input, strlen(if_host_prefix))) {
@@ -500,11 +500,11 @@ CURLcode Curl_parse_interface(const char *input,
     host_part = memchr(input, '!', len);
     if(!host_part || !*(host_part + 1))
       return CURLE_BAD_FUNCTION_ARGUMENT;
-    *iface = Curl_memdup0(input, host_part - input);
+    *iface = curlx_memdup0(input, host_part - input);
     if(!*iface)
       return CURLE_OUT_OF_MEMORY;
     ++host_part;
-    *host = Curl_memdup0(host_part, len - (host_part - input));
+    *host = curlx_memdup0(host_part, len - (host_part - input));
     if(!*host) {
       curlx_free(*iface);
       *iface = NULL;
@@ -515,7 +515,7 @@ CURLcode Curl_parse_interface(const char *input,
 
   if(!*input)
     return CURLE_BAD_FUNCTION_ARGUMENT;
-  *dev = Curl_memdup0(input, len);
+  *dev = curlx_memdup0(input, len);
   return *dev ? CURLE_OK : CURLE_OUT_OF_MEMORY;
 }
 
index 33484888ed390aea3211532c4681a2daf443f7ca..d6a045d22ea0a4545d511de618b8deac8f2d9c44 100644 (file)
 /* Define if you have the socket function. */
 #define HAVE_SOCKET 1
 
-/* Define if you have the strdup function. */
-#define HAVE_STRDUP 1
-
 /* Define if you have the utime function. */
 #define HAVE_UTIME 1
 
index 537bb7f1ed580f8ca5fb9657310763a01a4ce41d..19d8fc85474cf205be8439b3574c901253cd7a40 100644 (file)
@@ -36,7 +36,7 @@
 #include "curl_get_line.h"
 #include "curl_memrchr.h"
 #include "parsedate.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "llist.h"
 #include "bufref.h"
 #include "curlx/strparse.h"
@@ -245,7 +245,7 @@ static char *sanitize_cookie_path(const char *cookie_path, size_t len)
   if(len > 1 && cookie_path[len - 1] == '/')
     len--;
 
-  return Curl_memdup0(cookie_path, len);
+  return curlx_memdup0(cookie_path, len);
 }
 
 /*
@@ -264,7 +264,7 @@ static CURLcode strstore(char **str, const char *newstr, size_t len)
     len++;
     newstr = "";
   }
-  *str = Curl_memdup0(newstr, len);
+  *str = curlx_memdup0(newstr, len);
   if(!*str)
     return CURLE_OUT_OF_MEMORY;
   return CURLE_OK;
@@ -694,7 +694,7 @@ static CURLcode parse_netscape(struct Cookie *co,
         ptr++;
         len--;
       }
-      co->domain = Curl_memdup0(ptr, len);
+      co->domain = curlx_memdup0(ptr, len);
       if(!co->domain)
         return CURLE_OUT_OF_MEMORY;
       break;
@@ -737,7 +737,7 @@ static CURLcode parse_netscape(struct Cookie *co,
         return CURLE_OK;
       break;
     case 5:
-      co->name = Curl_memdup0(ptr, len);
+      co->name = curlx_memdup0(ptr, len);
       if(!co->name)
         return CURLE_OUT_OF_MEMORY;
       else {
@@ -749,7 +749,7 @@ static CURLcode parse_netscape(struct Cookie *co,
       }
       break;
     case 6:
-      co->value = Curl_memdup0(ptr, len);
+      co->value = curlx_memdup0(ptr, len);
       if(!co->value)
         return CURLE_OUT_OF_MEMORY;
       break;
@@ -1008,7 +1008,7 @@ Curl_cookie_add(struct Curl_easy *data,
     goto fail;
 
   /* clone the stack struct into heap */
-  co = Curl_memdup(&comem, sizeof(comem));
+  co = curlx_memdup(&comem, sizeof(comem));
   if(!co) {
     co = &comem;
     result = CURLE_OUT_OF_MEMORY;
index eb7740d6a254f6958e6f322c6e302f53bd538103..6f564eff1eda546a75b55b13c9ccfd5339998a81 100644 (file)
@@ -1077,6 +1077,14 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
 
 /* Allocator macros */
 
+#ifdef _WIN32
+#define CURLX_STRDUP_LOW _strdup
+#elif !defined(HAVE_STRDUP)
+#define CURLX_STRDUP_LOW curlx_strdup_low
+#else
+#define CURLX_STRDUP_LOW strdup
+#endif
+
 #ifdef CURL_MEMDEBUG
 
 #define curlx_strdup(ptr)          curl_dbg_strdup(ptr, __LINE__, __FILE__)
@@ -1104,11 +1112,7 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
 #define curlx_realloc              Curl_crealloc
 #define curlx_free                 Curl_cfree
 #else /* !BUILDING_LIBCURL */
-#ifdef _WIN32
-#define curlx_strdup               _strdup
-#else
-#define curlx_strdup               strdup
-#endif
+#define curlx_strdup               CURLX_STRDUP_LOW
 #define curlx_malloc               malloc
 #define curlx_calloc               calloc
 #define curlx_realloc              realloc
@@ -1117,7 +1121,7 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
 
 #ifdef _WIN32
 #ifdef UNICODE
-#define curlx_tcsdup               Curl_wcsdup
+#define curlx_tcsdup               curlx_wcsdup
 #else
 #define curlx_tcsdup               curlx_strdup
 #endif
index 6e272690054b0166f2c4358c2384e61f87e5bc61..1d4cf925d645b75c0fe0ffe59e9a1ae4858b2982 100644 (file)
@@ -26,7 +26,7 @@
 #ifdef USE_WINDOWS_SSPI
 
 #include "curl_sspi.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "curlx/multibyte.h"
 
 /* Pointer to SSPI dispatch table */
index 1733625fd8d06b88276144f321a45e6a1e903bc5..80da456f57e993efd662d72d542eb5130e37872d 100644 (file)
  * be.
  */
 
-#include "basename.h"
-/* for curlx_basename() function */
-
-#include "binmode.h"
-/* "binmode.h" provides macro CURLX_SET_BINMODE() */
-
-#include "nonblock.h"
-/* "nonblock.h" provides curlx_nonblock() */
-
-#include "multibyte.h"
-/* "multibyte.h" provides these functions and macros:
-
-  curlx_convert_UTF8_to_wchar()
-  curlx_convert_wchar_to_UTF8()
-  curlx_convert_UTF8_to_tchar()
-  curlx_convert_tchar_to_UTF8()
-*/
-
-#include "version_win32.h"
-/* provides curlx_verify_windows_version() */
-
-#include "strerr.h"
-/* The curlx_strerror() function */
-
-#include "strparse.h"
-/* The curlx_str_* parsing functions */
-
-#include "strcopy.h"
-/* curlx_strcopy */
-
-#include "dynbuf.h"
-/* The curlx_dyn_* functions */
-
-#include "fopen.h"
-/* The curlx_f* functions */
-
-#include "base64.h"
-#include "timeval.h"
-#include "timediff.h"
-
-#include "wait.h"
-/* for curlx_wait_ms */
-
-#include "winapi.h"
-/* for curlx_winapi_strerror */
-
-#include "inet_pton.h"
-/* for curlx_inet_pton */
-
-#include "inet_ntop.h"
-/* for curlx_inet_ntop */
+#include "base64.h" /* for curlx_base64* */
+#include "basename.h" /* for curlx_basename() */
+#include "binmode.h" /* for macro CURLX_SET_BINMODE() */
+#include "dynbuf.h" /* for curlx_dyn_*() */
+#include "fopen.h" /* for curlx_f*() */
+#include "inet_ntop.h" /* for curlx_inet_ntop() */
+#include "inet_pton.h" /* for curlx_inet_pton() */
+#include "multibyte.h" /* for curlx_convert_*() */
+#include "nonblock.h" /* for curlx_nonblock() */
+#include "strcopy.h" /* for curlx_strcopy() */
+#include "strdup.h" /* for curlx_memdup*() and curlx_tcsdup() */
+#include "strerr.h" /* for curlx_strerror() */
+#include "strparse.h" /* for curlx_str_* parsing functions */
+#include "timediff.h" /* for timediff_t type and related functions */
+#include "timeval.h" /* for curlx_now type and related functions */
+#include "version_win32.h" /* for curlx_verify_windows_version() */
+#include "wait.h" /* for curlx_wait_ms() */
+#include "winapi.h" /* for curlx_winapi_strerror() */
 
 #endif /* HEADER_CURL_CURLX_H */
index 158d4d044ae78c38e70b561bbe20b486fca45c85..22062c3bfa5c39957dd1eb5205577ab88056bf3d 100644 (file)
@@ -102,7 +102,7 @@ static CURLcode dyn_nappend(struct dynbuf *s,
   }
 
   if(a != s->allc) {
-    /* this logic is not using Curl_saferealloc() to make the tool not have to
+    /* this logic is not using curlx_saferealloc() to make the tool not have to
        include that as well when it uses this code */
     void *p = curlx_realloc(s->bufr, a);
     if(!p) {
similarity index 86%
rename from lib/strdup.c
rename to lib/curlx/strdup.c
index e97ae3588349cde2d39564b6b6e55fddc3b19b42..0d349e5c8a6640745b05209d8adad6ad0d1d9897 100644 (file)
@@ -21,7 +21,7 @@
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "curl_setup.h"
+#include "../curl_setup.h"
 
 #ifdef _WIN32
 #include <wchar.h>
 
 #include "strdup.h"
 
-#ifndef HAVE_STRDUP
-char *Curl_strdup(const char *str)
-{
-  size_t len;
-  char *newstr;
-
-  if(!str)
-    return NULL;
-
-  len = strlen(str) + 1;
-
-  newstr = curlx_malloc(len);
-  if(!newstr)
-    return NULL;
-
-  memcpy(newstr, str, len);
-  return newstr;
-}
-#endif
-
 #ifdef _WIN32
 /***************************************************************************
  *
- * Curl_wcsdup(source)
+ * curlx_wcsdup(source)
  *
  * Copies the 'source' wchar string to a newly allocated buffer (that is
- * returned).
+ * returned). Used by macro curlx_tcsdup().
  *
  * Returns the new pointer or NULL on failure.
  *
  ***************************************************************************/
-wchar_t *Curl_wcsdup(const wchar_t *src)
+wchar_t *curlx_wcsdup(const wchar_t *src)
 {
   size_t length = wcslen(src);
 
   if(length > (SIZE_MAX / sizeof(wchar_t)) - 1)
     return (wchar_t *)NULL; /* integer overflow */
 
-  return (wchar_t *)Curl_memdup(src, (length + 1) * sizeof(wchar_t));
+  return (wchar_t *)curlx_memdup(src, (length + 1) * sizeof(wchar_t));
+}
+#elif !defined(HAVE_STRDUP)
+char *curlx_strdup_low(const char *str)
+{
+  size_t len;
+  char *newstr;
+
+  if(!str)
+    return NULL;
+
+  len = strlen(str) + 1;
+
+  newstr = curlx_malloc(len);
+  if(!newstr)
+    return NULL;
+
+  memcpy(newstr, str, len);
+  return newstr;
 }
 #endif
 
 /***************************************************************************
  *
- * Curl_memdup(source, length)
+ * curlx_memdup(source, length)
  *
  * Copies the 'source' data to a newly allocated buffer (that is
  * returned). Copies 'length' bytes.
@@ -81,7 +79,7 @@ wchar_t *Curl_wcsdup(const wchar_t *src)
  * Returns the new pointer or NULL on failure.
  *
  ***************************************************************************/
-void *Curl_memdup(const void *src, size_t length)
+void *curlx_memdup(const void *src, size_t length)
 {
   void *buffer = curlx_malloc(length);
   if(!buffer)
@@ -94,7 +92,7 @@ void *Curl_memdup(const void *src, size_t length)
 
 /***************************************************************************
  *
- * Curl_memdup0(source, length)
+ * curlx_memdup0(source, length)
  *
  * Copies the 'source' string to a newly allocated buffer (that is returned).
  * Copies 'length' bytes then adds a null-terminator.
@@ -102,7 +100,7 @@ void *Curl_memdup(const void *src, size_t length)
  * Returns the new pointer or NULL on failure.
  *
  ***************************************************************************/
-void *Curl_memdup0(const char *src, size_t length)
+void *curlx_memdup0(const char *src, size_t length)
 {
   char *buf = (length < SIZE_MAX) ? curlx_malloc(length + 1) : NULL;
   if(!buf)
@@ -117,7 +115,7 @@ void *Curl_memdup0(const char *src, size_t length)
 
 /***************************************************************************
  *
- * Curl_saferealloc(ptr, size)
+ * curlx_saferealloc(ptr, size)
  *
  * Does a normal curlx_realloc(), but will free the data pointer if the realloc
  * fails. If 'size' is non-zero, it will free the data and return a failure.
@@ -129,7 +127,7 @@ void *Curl_memdup0(const char *src, size_t length)
  * Returns the new pointer or NULL on failure.
  *
  ***************************************************************************/
-void *Curl_saferealloc(void *ptr, size_t size)
+void *curlx_saferealloc(void *ptr, size_t size)
 {
   void *datap = curlx_realloc(ptr, size);
   if(size && !datap)
similarity index 71%
rename from lib/strdup.h
rename to lib/curlx/strdup.h
index cd01ffbdb8949acb3a7cad8376ec840b23c75d93..420385dcd2cf4c8cd06e7b4191d5da24540c59ce 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef HEADER_CURL_STRDUP_H
-#define HEADER_CURL_STRDUP_H
+#ifndef HEADER_CURLX_STRDUP_H
+#define HEADER_CURLX_STRDUP_H
 /***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "curl_setup.h"
+#include "../curl_setup.h"
 
-#ifndef HAVE_STRDUP
-char *Curl_strdup(const char *str);
-#endif
 #ifdef _WIN32
-wchar_t *Curl_wcsdup(const wchar_t *src);
+wchar_t *curlx_wcsdup(const wchar_t *src);  /* for curlx_tcsdup() */
+#elif !defined(HAVE_STRDUP)
+char *curlx_strdup_low(const char *str);
 #endif
-void *Curl_memdup(const void *src, size_t buffer_length);
-void *Curl_saferealloc(void *ptr, size_t size);
-void *Curl_memdup0(const char *src, size_t length);
-#endif /* HEADER_CURL_STRDUP_H */
+void *curlx_memdup(const void *src, size_t buffer_length);
+void *curlx_memdup0(const char *src, size_t length);
+void *curlx_saferealloc(void *ptr, size_t size);
+#endif /* HEADER_CURLX_STRDUP_H */
index fd22eeefbcce013417c967bf944728fa4225b7ae..5401256bf895aff995b26184bac2d436dcae2694 100644 (file)
--- a/lib/doh.c
+++ b/lib/doh.c
@@ -33,7 +33,7 @@
 #include "multiif.h"
 #include "url.h"
 #include "connect.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "curlx/dynbuf.h"
 #include "escape.h"
 #include "urlapi-int.h"
@@ -592,7 +592,7 @@ static DOHcode doh_store_https(const unsigned char *doh, int index,
   /* silently ignore RRs over the limit */
   if(d->numhttps_rrs < DOH_MAX_HTTPS) {
     struct dohhttps_rr *h = &d->https_rrs[d->numhttps_rrs];
-    h->val = Curl_memdup(&doh[index], len);
+    h->val = curlx_memdup(&doh[index], len);
     if(!h->val)
       return DOH_OUT_OF_MEM;
     h->len = len;
index a441d0e4f6cbf4eabe9fc8edd7c1272ca3655f1b..b30ce2ace41f926c9cb7cc1ec2fedb53850c770b 100644 (file)
@@ -51,7 +51,7 @@
 #include "url.h"
 #include "getinfo.h"
 #include "hostip.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "easyif.h"
 #include "multiif.h"
 #include "multi_ev.h"
@@ -94,19 +94,6 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
 
 #endif
 
-/*
- * strdup (and other memory functions) is redefined in complicated
- * ways, but at this point it must be defined as the system-supplied strdup
- * so the callback pointer is initialized correctly.
- */
-#ifdef _WIN32
-#define system_strdup _strdup
-#elif defined(HAVE_STRDUP)
-#define system_strdup strdup
-#else
-#define system_strdup Curl_strdup
-#endif
-
 #if defined(_MSC_VER) && defined(_DLL)
 #  pragma warning(push)
 #  pragma warning(disable:4232) /* MSVC extension, dllimport identity */
@@ -119,7 +106,7 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
 curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
 curl_free_callback Curl_cfree = (curl_free_callback)free;
 curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
-curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
 curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
 
 #if defined(_MSC_VER) && defined(_DLL)
@@ -144,7 +131,7 @@ static CURLcode global_init(long flags, bool memoryfuncs)
     Curl_cmalloc = (curl_malloc_callback)malloc;
     Curl_cfree = (curl_free_callback)free;
     Curl_crealloc = (curl_realloc_callback)realloc;
-    Curl_cstrdup = (curl_strdup_callback)system_strdup;
+    Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
     Curl_ccalloc = (curl_calloc_callback)calloc;
   }
 
@@ -919,9 +906,9 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
     if(src->set.postfieldsize == -1)
       dst->set.str[i] = curlx_strdup(src->set.str[i]);
     else
-      /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
-      dst->set.str[i] = Curl_memdup(src->set.str[i],
-                                    curlx_sotouz(src->set.postfieldsize));
+      /* postfieldsize is curl_off_t, curlx_memdup() takes a size_t ... */
+      dst->set.str[i] = curlx_memdup(src->set.str[i],
+                                     curlx_sotouz(src->set.postfieldsize));
     if(!dst->set.str[i])
       return CURLE_OUT_OF_MEMORY;
     /* point to the new copy */
index b22c2559892dcbcbc4cfc8bf1e18304b052d0f1b..b5bd1206f1068e46acb8677b8eb55772faa95047 100644 (file)
@@ -31,7 +31,7 @@ struct Curl_easy;
 
 #include "urldata.h" /* for struct Curl_easy */
 #include "mime.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "bufref.h"
 #include "curlx/fopen.h"
 
@@ -696,7 +696,7 @@ static CURLcode setname(curl_mimepart *part, const char *name, size_t len)
 
   if(!name || !len)
     return curl_mime_name(part, name);
-  zname = Curl_memdup0(name, len);
+  zname = curlx_memdup0(name, len);
   if(!zname)
     return CURLE_OUT_OF_MEMORY;
   res = curl_mime_name(part, zname);
index 24e4796c88b23227b401a293a4c796ecaad081e9..da21e1a828adaccad6e909d9d535c9ca7daf7951 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -65,7 +65,7 @@
 #include "multiif.h"
 #include "url.h"
 #include "http_proxy.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "curlx/strerr.h"
 #include "curlx/strparse.h"
 
@@ -3195,7 +3195,7 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data,
         ptr++;
       for(start = ptr; *ptr && *ptr != ' '; ptr++)
         ;
-      os = Curl_memdup0(start, ptr - start);
+      os = curlx_memdup0(start, ptr - start);
       if(!os)
         return CURLE_OUT_OF_MEMORY;
 
@@ -3578,7 +3578,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status,
           else
             /* file is url-decoded */
             pathLen -= ftpc->file ? strlen(ftpc->file) : 0;
-          ftpc->prevpath = Curl_memdup0(rawPath, pathLen);
+          ftpc->prevpath = curlx_memdup0(rawPath, pathLen);
         }
         else
           ftpc->prevpath = NULL; /* no path */
index 26a15ad75e2c0374928356ab1968c39948fac56c..b5568930287361700cd5a4c7cea6d52fe8cf626b 100644 (file)
@@ -77,7 +77,7 @@
 #include "http2.h"
 #include "cfilters.h"
 #include "connect.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "altsvc.h"
 #include "hsts.h"
 #include "rtsp.h"
@@ -200,7 +200,7 @@ static CURLcode copy_custom_value(const char *header, char **valp)
     curlx_str_untilnl(&header, &out, MAX_HTTP_RESP_HEADER_SIZE);
     curlx_str_trimblanks(&out);
 
-    *valp = Curl_memdup0(curlx_str(&out), curlx_strlen(&out));
+    *valp = curlx_memdup0(curlx_str(&out), curlx_strlen(&out));
     if(*valp)
       return CURLE_OK;
     return CURLE_OUT_OF_MEMORY;
@@ -227,7 +227,7 @@ char *Curl_copy_header_value(const char *header)
      !curlx_str_single(&header, ':')) {
     curlx_str_untilnl(&header, &out, MAX_HTTP_RESP_HEADER_SIZE);
     curlx_str_trimblanks(&out);
-    return Curl_memdup0(curlx_str(&out), curlx_strlen(&out));
+    return curlx_memdup0(curlx_str(&out), curlx_strlen(&out));
   }
   /* bad input, should never happen */
   DEBUGASSERT(0);
@@ -4659,17 +4659,17 @@ CURLcode Curl_http_req_make(struct httpreq **preq,
 #pragma GCC diagnostic pop
 #endif
   if(scheme) {
-    req->scheme = Curl_memdup0(scheme, s_len);
+    req->scheme = curlx_memdup0(scheme, s_len);
     if(!req->scheme)
       goto out;
   }
   if(authority) {
-    req->authority = Curl_memdup0(authority, a_len);
+    req->authority = curlx_memdup0(authority, a_len);
     if(!req->authority)
       goto out;
   }
   if(path) {
-    req->path = Curl_memdup0(path, p_len);
+    req->path = curlx_memdup0(path, p_len);
     if(!req->path)
       goto out;
   }
index 2205b03d090faadc0c412a2eebe913bd09d388c7..f1d0556fcf87213e9427985fb3a23443db179cd0 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "urldata.h"
 #include "strcase.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "http_aws_sigv4.h"
 #include "curl_sha256.h"
 #include "transfer.h"
@@ -405,7 +405,7 @@ static CURLcode make_headers(struct Curl_easy *data,
     if(data->state.aptr.host) {
       /* remove /r/n as the separator for canonical request must be '\n' */
       size_t pos = strcspn(data->state.aptr.host, "\n\r");
-      fullhost = Curl_memdup0(data->state.aptr.host, pos);
+      fullhost = curlx_memdup0(data->state.aptr.host, pos);
     }
     else
       fullhost = curl_maprintf("host:%s", hostname);
index d642a4c9049f091f6219b10d88f68dea5f7adac5..169a0b8d4a1f855ae6d5d8237aef85872d6ce20b 100644 (file)
@@ -29,7 +29,7 @@
 #include "httpsrr.h"
 #include "connect.h"
 #include "curl_trc.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 
 static CURLcode httpsrr_decode_alpn(const uint8_t *cp, size_t len,
                                     unsigned char *alpns)
@@ -92,7 +92,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data,
     if(!vlen || (vlen & 3)) /* the size must be 4-byte aligned */
       return CURLE_BAD_FUNCTION_ARGUMENT;
     curlx_free(hi->ipv4hints);
-    hi->ipv4hints = Curl_memdup(val, vlen);
+    hi->ipv4hints = curlx_memdup(val, vlen);
     if(!hi->ipv4hints)
       return CURLE_OUT_OF_MEMORY;
     hi->ipv4hints_len = vlen;
@@ -102,7 +102,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data,
     if(!vlen)
       return CURLE_BAD_FUNCTION_ARGUMENT;
     curlx_free(hi->echconfiglist);
-    hi->echconfiglist = Curl_memdup(val, vlen);
+    hi->echconfiglist = curlx_memdup(val, vlen);
     if(!hi->echconfiglist)
       return CURLE_OUT_OF_MEMORY;
     hi->echconfiglist_len = vlen;
@@ -112,7 +112,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data,
     if(!vlen || (vlen & 15)) /* the size must be 16-byte aligned */
       return CURLE_BAD_FUNCTION_ARGUMENT;
     curlx_free(hi->ipv6hints);
-    hi->ipv6hints = Curl_memdup(val, vlen);
+    hi->ipv6hints = curlx_memdup(val, vlen);
     if(!hi->ipv6hints)
       return CURLE_OUT_OF_MEMORY;
     hi->ipv6hints_len = vlen;
@@ -134,7 +134,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data,
 struct Curl_https_rrinfo *
 Curl_httpsrr_dup_move(struct Curl_https_rrinfo *rrinfo)
 {
-  struct Curl_https_rrinfo *dup = Curl_memdup(rrinfo, sizeof(*rrinfo));
+  struct Curl_https_rrinfo *dup = curlx_memdup(rrinfo, sizeof(*rrinfo));
   if(dup)
     memset(rrinfo, 0, sizeof(*rrinfo));
   return dup;
index 5c845a2745da21d975d0678c9320b858128e833e..c460cf65b9752c8a8441d038dd08b8a2668fc7b5 100644 (file)
@@ -30,7 +30,7 @@ struct Curl_easy;
 #include "sendf.h"
 #include "curl_trc.h"
 #include "transfer.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "curlx/basename.h"
 #include "curlx/strcopy.h"
 #include "curlx/fopen.h"
@@ -1281,7 +1281,7 @@ CURLcode curl_mime_data(curl_mimepart *part, const char *ptr, size_t datasize)
     if(datasize == CURL_ZERO_TERMINATED)
       datasize = strlen(ptr);
 
-    part->data = Curl_memdup0(ptr, datasize);
+    part->data = curlx_memdup0(ptr, datasize);
     if(!part->data)
       return CURLE_OUT_OF_MEMORY;
 
index 55d970c4f1f1722466849a462dd5b9827011c3f4..fdb09f232097032e1e1dfab45c98eaa4501065b4 100644 (file)
@@ -71,7 +71,7 @@
 #include "bufref.h"
 #include "curl_sasl.h"
 #include "curl_md5.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 
 /* Authentication type flags */
 #define POP3_TYPE_CLEARTEXT (1 << 0)
@@ -826,7 +826,7 @@ static CURLcode pop3_state_servergreet_resp(struct Curl_easy *data,
          therefore do not use APOP authentication. */
       if(at) {
         /* dupe the timestamp */
-        pop3c->apoptimestamp = Curl_memdup0(lt, timestamplen);
+        pop3c->apoptimestamp = curlx_memdup0(lt, timestamplen);
         if(!pop3c->apoptimestamp)
           return CURLE_OUT_OF_MEMORY;
         /* Store the APOP capability */
index 69bfb81c06b702208f55db905bac65a503e521af..038982e988c17addce42adf8bee404d33cf238cc 100644 (file)
@@ -38,7 +38,7 @@
 #include "select.h"
 #include "connect.h"
 #include "cfilters.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "bufref.h"
 #include "curlx/strparse.h"
 
@@ -1028,7 +1028,7 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header)
        */
 
       /* Copy the id substring into a new buffer */
-      data->set.str[STRING_RTSP_SESSION_ID] = Curl_memdup0(start, idlen);
+      data->set.str[STRING_RTSP_SESSION_ID] = curlx_memdup0(start, idlen);
       if(!data->set.str[STRING_RTSP_SESSION_ID])
         return CURLE_OUT_OF_MEMORY;
     }
index 31b1ca01ee4b245370ab851083dbd9f8fc5c823c..e6476dfaf30c2413e630ccd8f20714ec81dcf130 100644 (file)
@@ -46,7 +46,7 @@
 #include "altsvc.h"
 #include "hsts.h"
 #include "tftp.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "escape.h"
 #include "bufref.h"
 
@@ -1920,7 +1920,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
            mark that postfields is used rather than read function or form
            data.
         */
-        char *p = Curl_memdup0(ptr, pflen);
+        char *p = curlx_memdup0(ptr, pflen);
         if(!p)
           return CURLE_OUT_OF_MEMORY;
         else {
index f24a3383826595fa1b9b7c840aabdc280da73e95..21722f072016b083a86e3cd50c8f85f8f04cf106 100644 (file)
@@ -33,7 +33,7 @@
 #include "connect.h"
 #include "curlx/nonblock.h"
 #include "socks.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 
 #if defined(__GNUC__) && defined(__APPLE__)
 #pragma GCC diagnostic push
@@ -135,7 +135,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf,
   /* prepare service name */
   if(strchr(serviceptr, '/')) {
     service.length = serviceptr_length;
-    service.value = Curl_memdup(serviceptr, service.length);
+    service.value = curlx_memdup(serviceptr, service.length);
     if(!service.value)
       return CURLE_OUT_OF_MEMORY;
 
@@ -374,7 +374,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf,
   }
   else {
     gss_send_token.length = 1;
-    gss_send_token.value = Curl_memdup(&gss_enc, gss_send_token.length);
+    gss_send_token.value = curlx_memdup(&gss_enc, gss_send_token.length);
     if(!gss_send_token.value) {
       Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL);
       return CURLE_OUT_OF_MEMORY;
index ddd0dc5b1453cbc86328b783c74e5a89c7ffd7c5..b0d5c1ab3925a14a1139b3020687780739061b84 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -94,7 +94,7 @@
 #include "http_proxy.h"
 #include "conncache.h"
 #include "multihandle.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "setopt.h"
 #include "altsvc.h"
 #include "curlx/dynbuf.h"
@@ -2431,13 +2431,13 @@ CURLcode Curl_parse_login_details(const char *login, const size_t len,
            (size_t)(login + len - osep)) - 1 : 0);
 
   /* Clone the user portion buffer, which can be zero length */
-  ubuf = Curl_memdup0(login, ulen);
+  ubuf = curlx_memdup0(login, ulen);
   if(!ubuf)
     goto error;
 
   /* Clone the password portion buffer */
   if(psep) {
-    pbuf = Curl_memdup0(&psep[1], plen);
+    pbuf = curlx_memdup0(&psep[1], plen);
     if(!pbuf)
       goto error;
   }
@@ -2446,7 +2446,7 @@ CURLcode Curl_parse_login_details(const char *login, const size_t len,
   if(optionsp) {
     char *obuf = NULL;
     if(olen) {
-      obuf = Curl_memdup0(&osep[1], olen);
+      obuf = curlx_memdup0(&osep[1], olen);
       if(!obuf)
         goto error;
     }
index 1b67d80a9da1fc63da9a399294e1df3ebf2705e5..d6a790b06e5b6ede34788e685d54f72cb096200a 100644 (file)
@@ -30,7 +30,7 @@
 #include "escape.h"
 #include "curlx/inet_pton.h"
 #include "curlx/inet_ntop.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
 #include "idn.h"
 #include "curlx/strparse.h"
 #include "curl_memrchr.h"
@@ -1025,7 +1025,7 @@ static CURLUcode handle_fragment(CURLU *u, const char *fragment,
       u->fragment = curlx_dyn_ptr(&enc);
     }
     else {
-      u->fragment = Curl_memdup0(fragment + 1, fraglen - 1);
+      u->fragment = curlx_memdup0(fragment + 1, fraglen - 1);
       if(!u->fragment)
         return CURLUE_OUT_OF_MEMORY;
     }
@@ -1049,7 +1049,7 @@ static CURLUcode handle_query(CURLU *u, const char *query,
       u->query = curlx_dyn_ptr(&enc);
     }
     else {
-      u->query = Curl_memdup0(query + 1, qlen - 1);
+      u->query = curlx_memdup0(query + 1, qlen - 1);
       if(!u->query)
         return CURLUE_OUT_OF_MEMORY;
     }
@@ -1083,7 +1083,7 @@ static CURLUcode handle_path(CURLU *u, const char *path,
   }
   else {
     if(!u->path) {
-      u->path = Curl_memdup0(path, pathlen);
+      u->path = curlx_memdup0(path, pathlen);
       if(!u->path)
         return CURLUE_OUT_OF_MEMORY;
       path = u->path;
@@ -1364,7 +1364,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what,
   bool urlencode = (flags & CURLU_URLENCODE) ? 1 : 0;
   bool punycode = (flags & CURLU_PUNYCODE) && (what == CURLUPART_HOST);
   bool depunyfy = (flags & CURLU_PUNY2IDN) && (what == CURLUPART_HOST);
-  char *part = Curl_memdup0(ptr, partlen);
+  char *part = curlx_memdup0(ptr, partlen);
   *partp = NULL;
   if(!part)
     return CURLUE_OUT_OF_MEMORY;
index 2fef875bff216508d66dd7bdc92138fcb9306b16..893838d2cdd5cedd92a6df5de70a342eaf48b6e5 100644 (file)
@@ -32,7 +32,7 @@
 #include "digest.h"
 #include "../curlx/multibyte.h"
 #include "../curl_trc.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "../strcase.h"
 #include "../strerror.h"
 
@@ -351,7 +351,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
   }
 
   /* Store the challenge for use later */
-  digest->input_token = (BYTE *)Curl_memdup(chlg, chlglen + 1);
+  digest->input_token = (BYTE *)curlx_memdup(chlg, chlglen + 1);
   if(!digest->input_token)
     return CURLE_OUT_OF_MEMORY;
 
@@ -612,7 +612,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
     Curl_sspi_free_identity(p_identity);
   }
 
-  resp = Curl_memdup0((const char *)output_token, output_token_len);
+  resp = curlx_memdup0((const char *)output_token, output_token_len);
   curlx_free(output_token);
   if(!resp) {
     return CURLE_OUT_OF_MEMORY;
index 21f815779a16ebaf1ce156d9ad9ada562d829ee4..d0aae81b80e4e18879d6e8f0f1ccedcf5b60a801 100644 (file)
@@ -38,7 +38,7 @@
 #include "../curl_trc.h"
 #include "../curl_ntlm_core.h"
 #include "../rand.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "../curl_endian.h"
 
 /* NTLM buffer fixed size, large enough for long user + host + domain */
@@ -267,8 +267,8 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data,
       }
 
       curlx_free(ntlm->target_info); /* replace any previous data */
-      ntlm->target_info = Curl_memdup(&type2[target_info_offset],
-                                      target_info_len);
+      ntlm->target_info = curlx_memdup(&type2[target_info_offset],
+                                       target_info_len);
       if(!ntlm->target_info)
         return CURLE_OUT_OF_MEMORY;
     }
index 9040df1b88e7b37aac8a7763b491cb73b9ffacb8..e0a0bebec3e0eff4f496092cded290fdc9a8383a 100644 (file)
@@ -28,7 +28,7 @@
 #include "vauth.h"
 #include "../curl_ntlm_core.h"
 #include "../curl_trc.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 
 /*
  * Curl_auth_is_ntlm_supported()
@@ -201,8 +201,8 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
   }
 
   /* Store the challenge for later use */
-  ntlm->input_token = Curl_memdup0(Curl_bufref_ptr(type2),
-                                   Curl_bufref_len(type2));
+  ntlm->input_token = curlx_memdup0(Curl_bufref_ptr(type2),
+                                    Curl_bufref_len(type2));
   if(!ntlm->input_token)
     return CURLE_OUT_OF_MEMORY;
   ntlm->input_token_len = Curl_bufref_len(type2);
index cc58d23e0e8110423bde7d23040ff240fa13df49..eb43bb9a34b8a0471432dee5748d4cc9ea4f0803 100644 (file)
@@ -50,7 +50,7 @@
 #include "../parsedate.h"
 #include "../connect.h" /* for the connect timeout */
 #include "../progress.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "../curlx/fopen.h"
 #include "x509asn1.h"
 
@@ -723,7 +723,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf,
               "and store in cache", sdata_len, alpn ? alpn : "-",
               earlydata_max);
   if(quic_tp && quic_tp_len) {
-    qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len);
+    qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len);
     if(!qtp_clone) {
       curlx_free(sdata);
       return CURLE_OUT_OF_MEMORY;
index 8e4912a45fd412d2313c7bc380b589b49bad07ec..c4eb921fe156b2539ba0bbf3fc0dd4a563a6e342 100644 (file)
@@ -65,7 +65,7 @@
 #include "vtls_scache.h"
 #include "x509asn1.h"
 #include "../connect.h" /* for the connect timeout */
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "../curl_sha256.h"
 
 /* ALPN for http2 */
@@ -521,8 +521,8 @@ static CURLcode mbed_connect_step1(struct Curl_cfilter *cf,
          provided the exact length). The function accepts PEM or DER
          formats, but we cannot assume if the user passed in a PEM
          format cert that it is null-terminated. */
-      unsigned char *newblob = Curl_memdup0(ca_info_blob->data,
-                                            ca_info_blob->len);
+      unsigned char *newblob = curlx_memdup0(ca_info_blob->data,
+                                             ca_info_blob->len);
       if(!newblob)
         return CURLE_OUT_OF_MEMORY;
 
@@ -620,8 +620,8 @@ static CURLcode mbed_connect_step1(struct Curl_cfilter *cf,
          provided the exact length). The function accepts PEM or DER
          formats, but we cannot assume if the user passed in a PEM
          format cert that it is null-terminated. */
-      unsigned char *newblob = Curl_memdup0(ssl_cert_blob->data,
-                                            ssl_cert_blob->len);
+      unsigned char *newblob = curlx_memdup0(ssl_cert_blob->data,
+                                             ssl_cert_blob->len);
       if(!newblob)
         return CURLE_OUT_OF_MEMORY;
       ret = mbedtls_x509_crt_parse(&backend->clicert, newblob,
index d5913538cb194b0946649c52afd8b32e7a819967..852477b3854babd59a25b02abaed7aef143170f7 100644 (file)
@@ -61,7 +61,7 @@
 #include "../curlx/strerr.h"
 #include "../curlx/strparse.h"
 #include "../curlx/strcopy.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "apple.h"
 
 #include <openssl/rand.h>
@@ -2703,7 +2703,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf,
     earlydata_max = SSL_SESSION_get_max_early_data(session);
 #endif
     if(quic_tp && quic_tp_len) {
-      qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len);
+      qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len);
       if(!qtp_clone) {
         result = CURLE_OUT_OF_MEMORY;
         goto out;
index d90c86d99ffc230d79a5e2b1981c08abe17450e2..7eba7843684c2375fefa90bbe583542d2073fc8d 100644 (file)
@@ -42,7 +42,7 @@
 #include "vtls_scache.h"
 #include "../curl_trc.h"
 #include "../connect.h" /* for the connect timeout */
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "../strerror.h"
 #include "../select.h" /* for the socket readiness */
 #include "../curlx/fopen.h"
index e7e412b488ddede3418aee0b9b1b53ab1c87f7d5..5fea3f38f3c31ac8d484a04539a0a86deec39586 100644 (file)
@@ -70,7 +70,7 @@
 #include "../connect.h"
 #include "../select.h"
 #include "../setopt.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "../curlx/strcopy.h"
 
 #ifdef USE_APPLE_SECTRUST
@@ -2039,7 +2039,7 @@ CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf,
       result = CURLE_SSL_CONNECT_ERROR;
       goto out;
     }
-    connssl->negotiated.alpn = Curl_memdup0((const char *)proto, proto_len);
+    connssl->negotiated.alpn = curlx_memdup0((const char *)proto, proto_len);
     if(!connssl->negotiated.alpn)
       return CURLE_OUT_OF_MEMORY;
   }
index 9eeb808bde36d314f8280b472f08d405675dc072..2026fe3ed57d0fd96748720ea486b3dddfbf3e63 100644 (file)
@@ -29,7 +29,7 @@
 #include "../curl_trc.h"
 #include "vtls_scache.h"
 #include "vtls_spack.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 
 #ifndef UINT16_MAX
 #define UINT16_MAX    0xffff
@@ -152,7 +152,7 @@ static CURLcode spack_decstr16(char **val, const uint8_t **src,
     return r;
   if(end - *src < slen)
     return CURLE_READ_ERROR;
-  *val = Curl_memdup0((const char *)(*src), slen);
+  *val = curlx_memdup0((const char *)(*src), slen);
   *src += slen;
   return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY;
 }
@@ -182,7 +182,7 @@ static CURLcode spack_decdata16(uint8_t **val, size_t *val_len,
     return r;
   if(end - *src < data_len)
     return CURLE_READ_ERROR;
-  *val = Curl_memdup0((const char *)(*src), data_len);
+  *val = curlx_memdup0((const char *)(*src), data_len);
   *val_len = data_len;
   *src += data_len;
   return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY;
index 750f1123a5b9c3dd45a36a8b88381da000d063c0..150ac7d9c01eecd62f025b7109615a5108c35654 100644 (file)
@@ -60,7 +60,7 @@
 #include "keylog.h"
 #include "../connect.h" /* for the connect timeout */
 #include "../progress.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
 #include "../curlx/strcopy.h"
 #include "x509asn1.h"
 
@@ -443,7 +443,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf,
     goto out;
   }
   if(quic_tp && quic_tp_len) {
-    qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len);
+    qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len);
     if(!qtp_clone) {
       curlx_free(sdata);
       return CURLE_OUT_OF_MEMORY;
index d17d92f829658a3de1711cbc2f72245244b08cf9..a416ac820a043557ee40b6bc17e4e60654f05a6a 100644 (file)
@@ -40,6 +40,7 @@ CURLX_CFILES = \
   ../lib/curlx/multibyte.c \
   ../lib/curlx/nonblock.c \
   ../lib/curlx/strcopy.c \
+  ../lib/curlx/strdup.c \
   ../lib/curlx/strerr.c \
   ../lib/curlx/strparse.c \
   ../lib/curlx/timediff.c \
@@ -58,6 +59,7 @@ CURLX_HFILES = \
   ../lib/curlx/nonblock.h \
   ../lib/curlx/snprintf.h \
   ../lib/curlx/strcopy.h \
+  ../lib/curlx/strdup.h \
   ../lib/curlx/strerr.h \
   ../lib/curlx/strparse.h \
   ../lib/curlx/timediff.h \
@@ -108,7 +110,6 @@ CURL_CFILES = \
   tool_setopt.c \
   tool_ssls.c \
   tool_stderr.c \
-  tool_strdup.c \
   tool_urlglob.c \
   tool_util.c \
   tool_vms.c \
@@ -154,7 +155,6 @@ CURL_HFILES = \
   tool_setup.h \
   tool_ssls.h \
   tool_stderr.h \
-  tool_strdup.h \
   tool_urlglob.h \
   tool_util.h \
   tool_version.h \
index c50fac6b32e794b98a80c09f7a8165c6dc1fb8da..e22c59694cf579f73ef16092da359d8105663ec7 100644 (file)
@@ -34,7 +34,6 @@
 #include "tool_cb_wrt.h"
 #include "tool_operate.h"
 #include "tool_libinfo.h"
-#include "tool_strdup.h"
 
 #ifdef _WIN32
 #define BOLD    "\x1b[1m"
@@ -98,7 +97,7 @@ static void write_linked_location(CURL *curl, const char *location,
     goto locout;
 
   /* Create a null-terminated and whitespace-stripped copy of Location: */
-  copyloc = memdup0(loc, llen);
+  copyloc = curlx_memdup0(loc, llen);
   if(!copyloc)
     goto locout;
 
@@ -154,7 +153,7 @@ static char *parse_filename(const char *ptr, size_t len, char stop)
   char *p;
   char *q;
 
-  copy = memdup0(ptr, len);
+  copy = curlx_memdup0(ptr, len);
   if(!copy)
     return NULL;
 
index 540c98695586fb4d05ea37ed975112d6e942014d..7b699054dfe179572521c17d608593e58d37d8e4 100644 (file)
@@ -36,7 +36,6 @@
 #include "tool_main.h"
 #include "tool_stderr.h"
 #include "tool_help.h"
-#include "tool_strdup.h"
 #include "var.h"
 
 #define ALLOW_BLANK TRUE
@@ -70,7 +69,7 @@ static ParameterError getstrn(char **str, const char *val,
   if(!allowblank && !val[0])
     return PARAM_BLANK_STRING;
 
-  *str = memdup0(val, len);
+  *str = curlx_memdup0(val, len);
   if(!*str)
     return PARAM_NO_MEM;
 
index 6f9c0a004c6177bdf545e265a9d7937ecf4ae468..e113de8ddae2cc41de16a38adb5c835d4addddb1 100644 (file)
@@ -62,12 +62,6 @@ extern FILE *tool_stderr;
 /* define what to use for unprintable characters */
 #define UNPRINTABLE_CHAR '.'
 
-#ifndef HAVE_STRDUP
-#include "tool_strdup.h"
-#undef Curl_strdup
-#define Curl_strdup tool_strdup
-#endif
-
 #ifndef tool_nop_stmt
 #define tool_nop_stmt do {} while(0)
 #endif
diff --git a/src/tool_strdup.c b/src/tool_strdup.c
deleted file mode 100644 (file)
index c799d1a..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "tool_strdup.h"
-
-#ifndef HAVE_STRDUP
-char *tool_strdup(const char *str)
-{
-  size_t len;
-  char *newstr;
-
-  if(!str)
-    return (char *)NULL;
-
-  len = strlen(str) + 1;
-
-  newstr = curlx_malloc(len);
-  if(!newstr)
-    return (char *)NULL;
-
-  memcpy(newstr, str, len);
-  return newstr;
-}
-#endif
-
-char *memdup0(const char *data, size_t len)
-{
-  char *p = curlx_malloc(len + 1);
-  if(!p)
-    return NULL;
-  if(len)
-    memcpy(p, data, len);
-  p[len] = 0;
-  return p;
-}
diff --git a/src/tool_strdup.h b/src/tool_strdup.h
deleted file mode 100644 (file)
index 0f121e2..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef HEADER_TOOL_STRDUP_H
-#define HEADER_TOOL_STRDUP_H
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "tool_setup.h"
-
-#ifndef HAVE_STRDUP
-extern char *tool_strdup(const char *str);
-#endif
-char *memdup0(const char *data, size_t len);
-
-#endif /* HEADER_TOOL_STRDUP_H */
index 8a482460fa9f798d80b0ba0869b43c421a43d037..4c5973875b2ef5a5a828220bd2d9f1c19549449f 100644 (file)
@@ -27,7 +27,6 @@
 #include "tool_doswin.h"
 #include "tool_urlglob.h"
 #include "tool_vms.h"
-#include "tool_strdup.h"
 
 static CURLcode globerror(struct URLGlob *glob, const char *err,
                           size_t pos, CURLcode error)
@@ -49,7 +48,7 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len)
   if(!pat->c.set.elem)
     return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
 
-  pat->c.set.elem[0] = memdup0(fixed, len);
+  pat->c.set.elem[0] = curlx_memdup0(fixed, len);
   if(!pat->c.set.elem[0]) {
     tool_safefree(pat->c.set.elem);
     return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
index 4cc1b640fa915f613ff8f0c5679e70687fc4374a..306ed1b02bcbec022ec8f11da63ca3898a908932 100644 (file)
--- a/src/var.c
+++ b/src/var.c
@@ -28,7 +28,6 @@
 #include "tool_msgs.h"
 #include "tool_paramhlp.h"
 #include "tool_writeout_json.h"
-#include "tool_strdup.h"
 #include "var.h"
 
 #define MAX_EXPAND_CONTENT 10000000
@@ -190,7 +189,7 @@ static ParameterError varfunc(char *c, /* content */
       curlx_free(c);
 
     clen = curlx_dyn_len(out);
-    c = memdup0(curlx_dyn_ptr(out), clen);
+    c = curlx_memdup0(curlx_dyn_ptr(out), clen);
     if(!c) {
       err = PARAM_NO_MEM;
       break;
@@ -357,7 +356,7 @@ static ParameterError addvariable(const char *name,
     memcpy(p->name, name, nlen);
     /* the null termination byte is already present from above */
 
-    p->content = contalloc ? content : memdup0(content, clen);
+    p->content = contalloc ? content : curlx_memdup0(content, clen);
     if(p->content) {
       p->clen = clen;
 
index 523833ea61cac9b734bfc990bbf84d143ab320ff..f888bbf156a48a525cac670c1d9f528ca50e3ada 100644 (file)
@@ -52,12 +52,7 @@ static void *custom_malloc(size_t size)
 static char *custom_strdup(const char *ptr)
 {
   seen++;
-#ifdef _WIN32
-  return _strdup(ptr);
-#else
-  /* !checksrc! disable BANNEDFUNC 1 */
-  return strdup(ptr);
-#endif
+  return CURLX_STRDUP_LOW(ptr);
 }
 
 static void *custom_realloc(void *ptr, size_t size)
index 3c383d9003e9ee4ea57c8cde885c9b9f39ba5ba4..361d9a5c521d1a2b622e8356225af14a006e9873 100644 (file)
 curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
 curl_free_callback Curl_cfree = (curl_free_callback)free;
 curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
-#ifdef _WIN32
-curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)_strdup;
-#else
-curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
-#endif
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
 curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
 
 #if defined(_MSC_VER) && defined(_DLL)
index 2fb655e159fae6d1915be42a538fbdc7dc6e7a58..3980c211419f5f1f67924d0e6122fb2d4accfeba 100644 (file)
@@ -16,5 +16,4 @@ allowfunc send
 allowfunc snprintf
 allowfunc socket
 allowfunc sscanf
-allowfunc strdup
 allowfunc vsnprintf
index 1de25f6863a70866c72e0ee96b071148ddd2db4e..bb887711756328bfd8144b739dcb8ab3c2b81f67 100644 (file)
@@ -69,10 +69,6 @@ extern const struct entry_s s_entries[];
 #  define snprintf _snprintf
 #endif
 
-#ifdef _WIN32
-#  define strdup _strdup
-#endif
-
 #ifdef _WIN32
 #  define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n)
 #elif defined(HAVE_STRCASECMP)
index 91e1b7f7bb779a2e4e3555d4fb4821723e011512..7b5a98958bccda6b0a9b5e0c5acbfb86d4b0c61a 100644 (file)
@@ -610,7 +610,7 @@ static int validate_access(struct testcase *test,
                             (long)our_getpid());
 
     logmsg("Are-we-friendly question received");
-    test->buffer = strdup(weare);
+    test->buffer = curlx_strdup(weare);
     test->rptr = test->buffer; /* set read pointer */
     test->bufsize = count;    /* set total count */
     test->rcount = count;     /* set data left to read */