easy: use a custom implementation of wcsdup on Windows

... so that malloc/free overrides from curl_global_init are used for
wcsdup correctly.

Closes #7540
This commit is contained in:
Jeff Mears 2021-08-06 14:27:42 -07:00 committed by Daniel Stenberg
parent 3e2a229783
commit 76e047fc27
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 30 additions and 1 deletions

View File

@ -117,7 +117,7 @@ curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
#if defined(WIN32) && defined(UNICODE)
curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
curl_wcsdup_callback Curl_cwcsdup = Curl_wcsdup;
#endif
#if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__)

View File

@ -24,6 +24,10 @@
#include <curl/curl.h>
#ifdef WIN32
#include <wchar.h>
#endif
#include "strdup.h"
#include "curl_memory.h"
@ -50,6 +54,28 @@ char *curlx_strdup(const char *str)
}
#endif
#ifdef WIN32
/***************************************************************************
*
* Curl_wcsdup(source)
*
* Copies the 'source' wchar string to a newly allocated buffer (that is
* returned).
*
* Returns the new pointer or NULL on failure.
*
***************************************************************************/
wchar_t *Curl_wcsdup(const wchar_t *src)
{
size_t length = wcslen(src);
if(length > (SIZE_T_MAX / sizeof(wchar_t)) - 1)
return (wchar_t *)NULL; /* integer overflow */
return (wchar_t *)Curl_memdup(src, (length + 1) * sizeof(wchar_t));
}
#endif
/***************************************************************************
*
* Curl_memdup(source, length)

View File

@ -26,6 +26,9 @@
#ifndef HAVE_STRDUP
extern char *curlx_strdup(const char *str);
#endif
#ifdef WIN32
wchar_t* Curl_wcsdup(const wchar_t* src);
#endif
void *Curl_memdup(const void *src, size_t buffer_length);
void *Curl_saferealloc(void *ptr, size_t size);