build: stop overriding standard memory allocation functions

Before this patch curl used the C preprocessor to override standard
memory allocation symbols: malloc, calloc, strdup, realloc, free.
The goal of these is to replace them with curl's debug wrappers in
`CURLDEBUG` builds, another was to replace them with the wrappers
calling user-defined allocators in libcurl. This solution needed a bunch
of workarounds to avoid breaking external headers: it relied on include
order to do the overriding last. For "unity" builds it needed to reset
overrides before external includes. Also in test apps, which are always
built as single source files. It also needed the `(symbol)` trick
to avoid overrides in some places. This would still not fix cases where
the standard symbols were macros. It was also fragile and difficult
to figure out which was the actual function behind an alloc or free call
in a specific piece of code. This in turn caused bugs where the wrong
allocator was accidentally called.

To avoid these problems, this patch replaces this solution with
`curlx_`-prefixed allocator macros, and mapping them _once_ to either
the libcurl wrappers, the debug wrappers or the standard ones, matching
the rest of the code in libtests.

This concludes the long journey to avoid redefining standard functions
in the curl codebase.

Note: I did not update `packages/OS400/*.c` sources. They did not
`#include` `curl_setup.h`, `curl_memory.h` or `memdebug.h`, meaning
the overrides were never applied to them. This may or may not have been
correct. For now I suppressed the direct use of standard allocators
via a local `.checksrc`. Probably they (except for `curlcl.c`) should be
updated to include `curl_setup.h` and use the `curlx_` macros.

This patch changes mappings in two places:
- `lib/curl_threads.c` in libtests: Before this patch it mapped to
  libcurl allocators. After, it maps to standard allocators, like
  the rest of libtests code.
- `units`: before this patch it mapped to standard allocators. After, it
  maps to libcurl allocators.

Also:
- drop all position-dependent `curl_memory.h` and `memdebug.h` includes,
  and delete the now unnecessary headers.
- rename `Curl_tcsdup` macro to `curlx_tcsdup` and define like the other
  allocators.
- map `curlx_strdup()` to `_strdup()` on Windows (was: `strdup()`).
  To fix warnings silenced via `_CRT_NONSTDC_NO_DEPRECATE`.
- multibyte: map `curlx_convert_*()` to `_strdup()` on Windows
  (was: `strdup()`).
- src: do not reuse the `strdup` name for the local replacement.
- lib509: call `_strdup()` on Windows (was: `strdup()`).
- test1132: delete test obsoleted by this patch.
- CHECKSRC.md: update text for `SNPRINTF`.
- checksrc: ban standard allocator symbols.

Follow-up to b12da22db1 #18866
Follow-up to db98daab05 #18844
Follow-up to 4deea9396b #18814
Follow-up to 9678ff5b1b #18776
Follow-up to 10bac43b87 #18774
Follow-up to 20142f5d06 #18634
Follow-up to bf7375ecc5 #18503
Follow-up to 9863599d69 #18502
Follow-up to 3bb5e58c10 #17827

Closes #19626
This commit is contained in:
Viktor Szakats 2025-10-08 02:33:19 +02:00
parent bfc3d131b6
commit 193cb00ce9
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
471 changed files with 1456 additions and 2785 deletions

View file

@ -38,10 +38,6 @@
#include "../curlx/warnless.h"
#include "../sendf.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_create_plain_message()
*

View file

@ -36,10 +36,6 @@
#include "../curl_md5.h"
#include "../curlx/warnless.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_create_cram_md5_message()

View file

@ -44,10 +44,6 @@
#include "../curlx/strparse.h"
#include "../rand.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
#ifndef USE_WINDOWS_SSPI
#define SESSION_ALGO 1 /* for algos with this bit set */
@ -174,7 +170,7 @@ static char *auth_digest_string_quoted(const char *source)
++s;
}
dest = malloc(n);
dest = curlx_malloc(n);
if(dest) {
char *d = dest;
s = source;
@ -426,7 +422,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
/* Calculate H(A2) */
ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
if(!ctxt) {
free(spn);
curlx_free(spn);
return CURLE_OUT_OF_MEMORY;
}
@ -444,7 +440,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
/* Now calculate the response hash */
ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
if(!ctxt) {
free(spn);
curlx_free(spn);
return CURLE_OUT_OF_MEMORY;
}
@ -477,7 +473,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
"response=%s,qop=%s",
userp, realm, nonce,
cnonce, nonceCount, spn, resp_hash_hex, qop);
free(spn);
curlx_free(spn);
if(!response)
return CURLE_OUT_OF_MEMORY;
@ -522,8 +518,8 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
/* Extract a value=content pair */
if(Curl_auth_digest_get_pair(chlg, value, content, &chlg)) {
if(curl_strequal(value, "nonce")) {
free(digest->nonce);
digest->nonce = strdup(content);
curlx_free(digest->nonce);
digest->nonce = curlx_strdup(content);
if(!digest->nonce)
return CURLE_OUT_OF_MEMORY;
}
@ -534,14 +530,14 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
}
}
else if(curl_strequal(value, "realm")) {
free(digest->realm);
digest->realm = strdup(content);
curlx_free(digest->realm);
digest->realm = curlx_strdup(content);
if(!digest->realm)
return CURLE_OUT_OF_MEMORY;
}
else if(curl_strequal(value, "opaque")) {
free(digest->opaque);
digest->opaque = strdup(content);
curlx_free(digest->opaque);
digest->opaque = curlx_strdup(content);
if(!digest->opaque)
return CURLE_OUT_OF_MEMORY;
}
@ -567,21 +563,21 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
/* Select only auth or auth-int. Otherwise, ignore */
if(foundAuth) {
free(digest->qop);
digest->qop = strdup(DIGEST_QOP_VALUE_STRING_AUTH);
curlx_free(digest->qop);
digest->qop = curlx_strdup(DIGEST_QOP_VALUE_STRING_AUTH);
if(!digest->qop)
return CURLE_OUT_OF_MEMORY;
}
else if(foundAuthInt) {
free(digest->qop);
digest->qop = strdup(DIGEST_QOP_VALUE_STRING_AUTH_INT);
curlx_free(digest->qop);
digest->qop = curlx_strdup(DIGEST_QOP_VALUE_STRING_AUTH_INT);
if(!digest->qop)
return CURLE_OUT_OF_MEMORY;
}
}
else if(curl_strequal(value, "algorithm")) {
free(digest->algorithm);
digest->algorithm = strdup(content);
curlx_free(digest->algorithm);
digest->algorithm = curlx_strdup(content);
if(!digest->algorithm)
return CURLE_OUT_OF_MEMORY;
@ -725,7 +721,7 @@ static CURLcode auth_create_digest_http_message(
return CURLE_OUT_OF_MEMORY;
result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis));
free(hashthis);
curlx_free(hashthis);
if(result)
return result;
convert_to_ascii(hashbuf, (unsigned char *)userh);
@ -748,7 +744,7 @@ static CURLcode auth_create_digest_http_message(
return CURLE_OUT_OF_MEMORY;
result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis));
free(hashthis);
curlx_free(hashthis);
if(result)
return result;
convert_to_ascii(hashbuf, ha1);
@ -760,7 +756,7 @@ static CURLcode auth_create_digest_http_message(
return CURLE_OUT_OF_MEMORY;
result = hash(hashbuf, (unsigned char *) tmp, strlen(tmp));
free(tmp);
curlx_free(tmp);
if(result)
return result;
convert_to_ascii(hashbuf, ha1);
@ -790,13 +786,13 @@ static CURLcode auth_create_digest_http_message(
result = hash(hashbuf, (const unsigned char *)"", 0);
if(result) {
free(hashthis);
curlx_free(hashthis);
return result;
}
convert_to_ascii(hashbuf, (unsigned char *)hashed);
hashthis2 = curl_maprintf("%s:%s", hashthis, hashed);
free(hashthis);
curlx_free(hashthis);
hashthis = hashthis2;
}
@ -804,7 +800,7 @@ static CURLcode auth_create_digest_http_message(
return CURLE_OUT_OF_MEMORY;
result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis));
free(hashthis);
curlx_free(hashthis);
if(result)
return result;
convert_to_ascii(hashbuf, ha2);
@ -821,7 +817,7 @@ static CURLcode auth_create_digest_http_message(
return CURLE_OUT_OF_MEMORY;
result = hash(hashbuf, (unsigned char *) hashthis, strlen(hashthis));
free(hashthis);
curlx_free(hashthis);
if(result)
return result;
convert_to_ascii(hashbuf, request_digest);
@ -845,18 +841,18 @@ static CURLcode auth_create_digest_http_message(
if(digest->realm)
realm_quoted = auth_digest_string_quoted(digest->realm);
else {
realm_quoted = malloc(1);
realm_quoted = curlx_malloc(1);
if(realm_quoted)
realm_quoted[0] = 0;
}
if(!realm_quoted) {
free(userp_quoted);
curlx_free(userp_quoted);
return CURLE_OUT_OF_MEMORY;
}
nonce_quoted = auth_digest_string_quoted(digest->nonce);
if(!nonce_quoted) {
free(realm_quoted);
free(userp_quoted);
curlx_free(realm_quoted);
curlx_free(userp_quoted);
return CURLE_OUT_OF_MEMORY;
}
@ -893,9 +889,9 @@ static CURLcode auth_create_digest_http_message(
uripath,
request_digest);
}
free(nonce_quoted);
free(realm_quoted);
free(userp_quoted);
curlx_free(nonce_quoted);
curlx_free(realm_quoted);
curlx_free(userp_quoted);
if(!response)
return CURLE_OUT_OF_MEMORY;
@ -905,12 +901,12 @@ static CURLcode auth_create_digest_http_message(
/* Append the opaque */
opaque_quoted = auth_digest_string_quoted(digest->opaque);
if(!opaque_quoted) {
free(response);
curlx_free(response);
return CURLE_OUT_OF_MEMORY;
}
tmp = curl_maprintf("%s, opaque=\"%s\"", response, opaque_quoted);
free(response);
free(opaque_quoted);
curlx_free(response);
curlx_free(opaque_quoted);
if(!tmp)
return CURLE_OUT_OF_MEMORY;
@ -920,7 +916,7 @@ static CURLcode auth_create_digest_http_message(
if(digest->algorithm) {
/* Append the algorithm */
tmp = curl_maprintf("%s, algorithm=%s", response, digest->algorithm);
free(response);
curlx_free(response);
if(!tmp)
return CURLE_OUT_OF_MEMORY;
@ -930,7 +926,7 @@ static CURLcode auth_create_digest_http_message(
if(digest->userhash) {
/* Append the userhash */
tmp = curl_maprintf("%s, userhash=true", response);
free(response);
curlx_free(response);
if(!tmp)
return CURLE_OUT_OF_MEMORY;

View file

@ -41,10 +41,6 @@
#include "../strcase.h"
#include "../strerror.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_is_digest_supported()
*
@ -135,14 +131,14 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
Curl_pSecFn->FreeContextBuffer(SecurityPackage);
/* Allocate our response buffer */
output_token = malloc(token_max);
output_token = curlx_malloc(token_max);
if(!output_token)
return CURLE_OUT_OF_MEMORY;
/* Generate our SPN */
spn = Curl_auth_build_spn(service, data->conn->host.name, NULL);
if(!spn) {
free(output_token);
curlx_free(output_token);
return CURLE_OUT_OF_MEMORY;
}
@ -150,8 +146,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
/* Populate our identity structure */
result = Curl_create_sspi_identity(userp, passwdp, &identity);
if(result) {
free(spn);
free(output_token);
curlx_free(spn);
curlx_free(output_token);
return result;
}
@ -171,8 +167,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
if(status != SEC_E_OK) {
Curl_sspi_free_identity(p_identity);
free(spn);
free(output_token);
curlx_free(spn);
curlx_free(output_token);
return CURLE_LOGIN_DENIED;
}
@ -208,8 +204,8 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
Curl_pSecFn->FreeCredentialsHandle(&credentials);
Curl_sspi_free_identity(p_identity);
free(spn);
free(output_token);
curlx_free(spn);
curlx_free(output_token);
if(status == SEC_E_INSUFFICIENT_MEMORY)
return CURLE_OUT_OF_MEMORY;
@ -233,7 +229,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
Curl_sspi_free_identity(p_identity);
/* Free the SPN */
free(spn);
curlx_free(spn);
return result;
}
@ -276,13 +272,13 @@ CURLcode Curl_override_sspi_http_realm(const char *chlg,
if(!domain.tchar_ptr)
return CURLE_OUT_OF_MEMORY;
dup_domain.tchar_ptr = Curl_tcsdup(domain.tchar_ptr);
dup_domain.tchar_ptr = curlx_tcsdup(domain.tchar_ptr);
if(!dup_domain.tchar_ptr) {
curlx_unicodefree(domain.tchar_ptr);
return CURLE_OUT_OF_MEMORY;
}
free(identity->Domain);
curlx_free(identity->Domain);
identity->Domain = dup_domain.tbyte_ptr;
identity->DomainLength = curlx_uztoul(_tcslen(dup_domain.tchar_ptr));
dup_domain.tchar_ptr = NULL;
@ -429,7 +425,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
/* Allocate the output buffer according to the max token size as indicated
by the security package */
output_token = malloc(token_max);
output_token = curlx_malloc(token_max);
if(!output_token) {
return CURLE_OUT_OF_MEMORY;
}
@ -495,7 +491,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
if(userp && *userp) {
/* Populate our identity structure */
if(Curl_create_sspi_identity(userp, passwdp, &identity)) {
free(output_token);
curlx_free(output_token);
return CURLE_OUT_OF_MEMORY;
}
@ -503,7 +499,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
if(Curl_override_sspi_http_realm((const char *) digest->input_token,
&identity)) {
Curl_sspi_free_identity(&identity);
free(output_token);
curlx_free(output_token);
return CURLE_OUT_OF_MEMORY;
}
@ -515,20 +511,20 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
p_identity = NULL;
if(userp) {
digest->user = strdup(userp);
digest->user = curlx_strdup(userp);
if(!digest->user) {
free(output_token);
curlx_free(output_token);
Curl_sspi_free_identity(p_identity);
return CURLE_OUT_OF_MEMORY;
}
}
if(passwdp) {
digest->passwd = strdup(passwdp);
digest->passwd = curlx_strdup(passwdp);
if(!digest->passwd) {
free(output_token);
curlx_free(output_token);
Curl_sspi_free_identity(p_identity);
Curl_safefree(digest->user);
return CURLE_OUT_OF_MEMORY;
@ -543,7 +539,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
&credentials, NULL);
if(status != SEC_E_OK) {
Curl_sspi_free_identity(p_identity);
free(output_token);
curlx_free(output_token);
return CURLE_LOGIN_DENIED;
}
@ -575,18 +571,18 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
Curl_pSecFn->FreeCredentialsHandle(&credentials);
Curl_sspi_free_identity(p_identity);
free(output_token);
curlx_free(output_token);
return CURLE_OUT_OF_MEMORY;
}
/* Allocate our new context handle */
digest->http_context = calloc(1, sizeof(CtxtHandle));
digest->http_context = curlx_calloc(1, sizeof(CtxtHandle));
if(!digest->http_context) {
Curl_pSecFn->FreeCredentialsHandle(&credentials);
curlx_unicodefree(spn);
Curl_sspi_free_identity(p_identity);
free(output_token);
curlx_free(output_token);
return CURLE_OUT_OF_MEMORY;
}
@ -610,7 +606,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
Curl_pSecFn->FreeCredentialsHandle(&credentials);
Curl_sspi_free_identity(p_identity);
free(output_token);
curlx_free(output_token);
Curl_safefree(digest->http_context);
@ -632,7 +628,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
}
resp = Curl_memdup0((const char *)output_token, output_token_len);
free(output_token);
curlx_free(output_token);
if(!resp) {
return CURLE_OUT_OF_MEMORY;
}

View file

@ -36,10 +36,6 @@
#include <gsasl.h>
/* The last 2 #include files should be in this order */
#include "../curl_memory.h"
#include "../memdebug.h"
bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
const char *mech,
struct gsasldata *gsasl)

View file

@ -37,10 +37,6 @@
#include "../curl_gssapi.h"
#include "../sendf.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
#if defined(__GNUC__) && defined(__APPLE__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
@ -120,12 +116,12 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
Curl_gss_log_error(data, "gss_import_name() failed: ",
major_status, minor_status);
free(spn);
curlx_free(spn);
return CURLE_AUTH_ERROR;
}
free(spn);
curlx_free(spn);
}
if(chlg) {
@ -258,7 +254,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
messagelen = 4;
if(authzid)
messagelen += strlen(authzid);
message = malloc(messagelen);
message = curlx_malloc(messagelen);
if(!message)
return CURLE_OUT_OF_MEMORY;
@ -285,7 +281,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
if(GSS_ERROR(major_status)) {
Curl_gss_log_error(data, "gss_wrap() failed: ",
major_status, minor_status);
free(message);
curlx_free(message);
return CURLE_AUTH_ERROR;
}
@ -295,7 +291,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
gss_release_buffer(&unused_status, &output_token);
/* Free the message buffer */
free(message);
curlx_free(message);
return result;
}

View file

@ -36,10 +36,6 @@
#include "../curlx/multibyte.h"
#include "../sendf.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_is_gssapi_supported()
*
@ -131,7 +127,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
Curl_pSecFn->FreeContextBuffer(SecurityPackage);
/* Allocate our response buffer */
krb5->output_token = malloc(krb5->token_max);
krb5->output_token = curlx_malloc(krb5->token_max);
if(!krb5->output_token)
return CURLE_OUT_OF_MEMORY;
}
@ -152,7 +148,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
krb5->p_identity = NULL;
/* Allocate our credentials handle */
krb5->credentials = calloc(1, sizeof(CredHandle));
krb5->credentials = curlx_calloc(1, sizeof(CredHandle));
if(!krb5->credentials)
return CURLE_OUT_OF_MEMORY;
@ -166,7 +162,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
return CURLE_LOGIN_DENIED;
/* Allocate our new context handle */
krb5->context = calloc(1, sizeof(CtxtHandle));
krb5->context = curlx_calloc(1, sizeof(CtxtHandle));
if(!krb5->context)
return CURLE_OUT_OF_MEMORY;
}
@ -340,7 +336,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
}
/* Allocate the trailer */
trailer = malloc(sizes.cbSecurityTrailer);
trailer = curlx_malloc(sizes.cbSecurityTrailer);
if(!trailer)
return CURLE_OUT_OF_MEMORY;
@ -348,7 +344,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
messagelen = 4;
if(authzid)
messagelen += strlen(authzid);
message = malloc(messagelen);
message = curlx_malloc(messagelen);
if(!message) {
result = CURLE_OUT_OF_MEMORY;
goto out;
@ -367,7 +363,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
memcpy(message + 4, authzid, messagelen - 4);
/* Allocate the padding */
padding = malloc(sizes.cbBlockSize);
padding = curlx_malloc(sizes.cbBlockSize);
if(!padding) {
result = CURLE_OUT_OF_MEMORY;
goto out;
@ -401,7 +397,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
/* Allocate the encryption (wrap) buffer */
appdatalen = wrap_buf[0].cbBuffer + wrap_buf[1].cbBuffer +
wrap_buf[2].cbBuffer;
appdata = malloc(appdatalen);
appdata = curlx_malloc(appdatalen);
if(!appdata) {
result = CURLE_OUT_OF_MEMORY;
goto out;
@ -416,9 +412,9 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
out:
/* Free all of our local buffers */
free(padding);
free(message);
free(trailer);
curlx_free(padding);
curlx_free(message);
curlx_free(trailer);
if(result)
return result;
@ -443,14 +439,14 @@ void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5)
/* Free our security context */
if(krb5->context) {
Curl_pSecFn->DeleteSecurityContext(krb5->context);
free(krb5->context);
curlx_free(krb5->context);
krb5->context = NULL;
}
/* Free our credentials handle */
if(krb5->credentials) {
Curl_pSecFn->FreeCredentialsHandle(krb5->credentials);
free(krb5->credentials);
curlx_free(krb5->credentials);
krb5->credentials = NULL;
}

View file

@ -48,10 +48,6 @@
#include "vauth.h"
#include "../curl_endian.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/* NTLM buffer fixed size, large enough for long user + host + domain */
#define NTLM_BUFSIZE 1024
@ -282,7 +278,7 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data,
return CURLE_BAD_CONTENT_ENCODING;
}
free(ntlm->target_info); /* replace any previous data */
curlx_free(ntlm->target_info); /* replace any previous data */
ntlm->target_info = Curl_memdup(&type2[target_info_offset],
target_info_len);
if(!ntlm->target_info)
@ -842,7 +838,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
result = Curl_bufref_memdup(out, ntlmbuf, size);
error:
free(ntlmv2resp); /* Free the dynamic buffer allocated for NTLMv2 */
curlx_free(ntlmv2resp); /* Free the dynamic buffer allocated for NTLMv2 */
Curl_auth_cleanup_ntlm(ntlm);

View file

@ -36,10 +36,6 @@
#include "../sendf.h"
#include "../strdup.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_is_ntlm_supported()
*
@ -117,7 +113,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
Curl_pSecFn->FreeContextBuffer(SecurityPackage);
/* Allocate our output buffer */
ntlm->output_token = malloc(ntlm->token_max);
ntlm->output_token = curlx_malloc(ntlm->token_max);
if(!ntlm->output_token)
return CURLE_OUT_OF_MEMORY;
@ -137,7 +133,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
ntlm->p_identity = NULL;
/* Allocate our credentials handle */
ntlm->credentials = calloc(1, sizeof(CredHandle));
ntlm->credentials = curlx_calloc(1, sizeof(CredHandle));
if(!ntlm->credentials)
return CURLE_OUT_OF_MEMORY;
@ -151,7 +147,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
return CURLE_LOGIN_DENIED;
/* Allocate our new context handle */
ntlm->context = calloc(1, sizeof(CtxtHandle));
ntlm->context = curlx_calloc(1, sizeof(CtxtHandle));
if(!ntlm->context)
return CURLE_OUT_OF_MEMORY;
@ -343,14 +339,14 @@ void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm)
/* Free our security context */
if(ntlm->context) {
Curl_pSecFn->DeleteSecurityContext(ntlm->context);
free(ntlm->context);
curlx_free(ntlm->context);
ntlm->context = NULL;
}
/* Free our credentials handle */
if(ntlm->credentials) {
Curl_pSecFn->FreeCredentialsHandle(ntlm->credentials);
free(ntlm->credentials);
curlx_free(ntlm->credentials);
ntlm->credentials = NULL;
}

View file

@ -36,10 +36,6 @@
#include "vauth.h"
#include "../curlx/warnless.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_create_oauth_bearer_message()
*

View file

@ -38,10 +38,6 @@
#include "../curlx/multibyte.h"
#include "../sendf.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
#if defined(__GNUC__) && defined(__APPLE__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
@ -131,12 +127,12 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
Curl_gss_log_error(data, "gss_import_name() failed: ",
major_status, minor_status);
free(spn);
curlx_free(spn);
return CURLE_AUTH_ERROR;
}
free(spn);
curlx_free(spn);
}
if(chlg64 && *chlg64) {

View file

@ -38,10 +38,6 @@
#include "../sendf.h"
#include "../strerror.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_is_spnego_supported()
*
@ -140,7 +136,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
Curl_pSecFn->FreeContextBuffer(SecurityPackage);
/* Allocate our output buffer */
nego->output_token = malloc(nego->token_max);
nego->output_token = curlx_malloc(nego->token_max);
if(!nego->output_token)
return CURLE_OUT_OF_MEMORY;
}
@ -161,7 +157,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
nego->p_identity = NULL;
/* Allocate our credentials handle */
nego->credentials = calloc(1, sizeof(CredHandle));
nego->credentials = curlx_calloc(1, sizeof(CredHandle));
if(!nego->credentials)
return CURLE_OUT_OF_MEMORY;
@ -175,7 +171,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
return CURLE_AUTH_ERROR;
/* Allocate our new context handle */
nego->context = calloc(1, sizeof(CtxtHandle));
nego->context = curlx_calloc(1, sizeof(CtxtHandle));
if(!nego->context)
return CURLE_OUT_OF_MEMORY;
}
@ -248,7 +244,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
&resp_desc, &attrs, NULL);
/* Free the decoded challenge as it is not required anymore */
free(chlg);
curlx_free(chlg);
if(GSS_ERROR(nego->status)) {
char buffer[STRERROR_LEN];
@ -305,7 +301,7 @@ CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego,
nego->output_token_length, outptr,
outlen);
if(!result && (!*outptr || !*outlen)) {
free(*outptr);
curlx_free(*outptr);
result = CURLE_REMOTE_ACCESS_DENIED;
}
@ -327,14 +323,14 @@ void Curl_auth_cleanup_spnego(struct negotiatedata *nego)
/* Free our security context */
if(nego->context) {
Curl_pSecFn->DeleteSecurityContext(nego->context);
free(nego->context);
curlx_free(nego->context);
nego->context = NULL;
}
/* Free our credentials handle */
if(nego->credentials) {
Curl_pSecFn->FreeCredentialsHandle(nego->credentials);
free(nego->credentials);
curlx_free(nego->credentials);
nego->credentials = NULL;
}

View file

@ -32,10 +32,6 @@
#include "../curlx/multibyte.h"
#include "../url.h"
/* The last #include files should be: */
#include "../curl_memory.h"
#include "../memdebug.h"
/*
* Curl_auth_build_spn()
*
@ -96,10 +92,10 @@ TCHAR *Curl_auth_build_spn(const char *service, const char *host,
must be freed by curlx_unicodefree we will dupe the result so that the
pointer this function returns can be normally free'd. */
tchar_spn = curlx_convert_UTF8_to_tchar(utf8_spn);
free(utf8_spn);
curlx_free(utf8_spn);
if(!tchar_spn)
return NULL;
dupe_tchar_spn = Curl_tcsdup(tchar_spn);
dupe_tchar_spn = curlx_tcsdup(tchar_spn);
curlx_unicodefree(tchar_spn);
return dupe_tchar_spn;
}
@ -170,7 +166,7 @@ static void ntlm_conn_dtor(void *key, size_t klen, void *entry)
(void)klen;
DEBUGASSERT(ntlm);
Curl_auth_cleanup_ntlm(ntlm);
free(ntlm);
curlx_free(ntlm);
}
struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy)
@ -179,7 +175,7 @@ struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy)
CURL_META_NTLM_CONN;
struct ntlmdata *ntlm = Curl_conn_meta_get(conn, key);
if(!ntlm) {
ntlm = calloc(1, sizeof(*ntlm));
ntlm = curlx_calloc(1, sizeof(*ntlm));
if(!ntlm ||
Curl_conn_meta_set(conn, key, ntlm, ntlm_conn_dtor))
return NULL;
@ -204,14 +200,14 @@ static void krb5_conn_dtor(void *key, size_t klen, void *entry)
(void)klen;
DEBUGASSERT(krb5);
Curl_auth_cleanup_gssapi(krb5);
free(krb5);
curlx_free(krb5);
}
struct kerberos5data *Curl_auth_krb5_get(struct connectdata *conn)
{
struct kerberos5data *krb5 = Curl_conn_meta_get(conn, CURL_META_KRB5_CONN);
if(!krb5) {
krb5 = calloc(1, sizeof(*krb5));
krb5 = curlx_calloc(1, sizeof(*krb5));
if(!krb5 ||
Curl_conn_meta_set(conn, CURL_META_KRB5_CONN, krb5, krb5_conn_dtor))
return NULL;
@ -230,14 +226,14 @@ static void gsasl_conn_dtor(void *key, size_t klen, void *entry)
(void)klen;
DEBUGASSERT(gsasl);
Curl_auth_gsasl_cleanup(gsasl);
free(gsasl);
curlx_free(gsasl);
}
struct gsasldata *Curl_auth_gsasl_get(struct connectdata *conn)
{
struct gsasldata *gsasl = Curl_conn_meta_get(conn, CURL_META_GSASL_CONN);
if(!gsasl) {
gsasl = calloc(1, sizeof(*gsasl));
gsasl = curlx_calloc(1, sizeof(*gsasl));
if(!gsasl ||
Curl_conn_meta_set(conn, CURL_META_GSASL_CONN, gsasl, gsasl_conn_dtor))
return NULL;
@ -256,7 +252,7 @@ static void nego_conn_dtor(void *key, size_t klen, void *entry)
(void)klen;
DEBUGASSERT(nego);
Curl_auth_cleanup_spnego(nego);
free(nego);
curlx_free(nego);
}
struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy)
@ -265,7 +261,7 @@ struct negotiatedata *Curl_auth_nego_get(struct connectdata *conn, bool proxy)
CURL_META_NEGO_CONN;
struct negotiatedata *nego = Curl_conn_meta_get(conn, key);
if(!nego) {
nego = calloc(1, sizeof(*nego));
nego = curlx_calloc(1, sizeof(*nego));
if(!nego ||
Curl_conn_meta_set(conn, key, nego, nego_conn_dtor))
return NULL;