diff --git a/docs/examples/.checksrc b/docs/examples/.checksrc index c47627467f..8c7b0c901e 100644 --- a/docs/examples/.checksrc +++ b/docs/examples/.checksrc @@ -4,17 +4,22 @@ allowfunc atoi allowfunc atol +allowfunc calloc allowfunc fclose allowfunc fdopen allowfunc fopen allowfunc fprintf +allowfunc free allowfunc gmtime allowfunc localtime +allowfunc malloc allowfunc open allowfunc printf +allowfunc realloc allowfunc snprintf allowfunc socket allowfunc sscanf +allowfunc strdup allowfunc strerror allowfunc vsnprintf diff --git a/docs/internals/CHECKSRC.md b/docs/internals/CHECKSRC.md index 1740b2bef5..091a4d3107 100644 --- a/docs/internals/CHECKSRC.md +++ b/docs/internals/CHECKSRC.md @@ -107,7 +107,7 @@ warnings are: `sizeof(int)` style. - `SNPRINTF` - Found use of `snprintf()`. Since we use an internal replacement - with a different return code etc, we prefer `msnprintf()`. + with a different return code etc, we prefer `curl_msnprintf()`. - `SPACEAFTERPAREN`: there was a space after open parenthesis, `( text`. diff --git a/docs/internals/CODE_STYLE.md b/docs/internals/CODE_STYLE.md index 7d37df4805..43b873be9b 100644 --- a/docs/internals/CODE_STYLE.md +++ b/docs/internals/CODE_STYLE.md @@ -352,10 +352,12 @@ This is the full list of functions generally banned. aprintf atoi atol + calloc fclose fdopen fopen fprintf + free freeaddrinfo freopen getaddrinfo @@ -368,11 +370,13 @@ This is the full list of functions generally banned. LoadLibraryExW LoadLibraryW localtime + malloc mbstowcs msnprintf mvsnprintf open printf + realloc recv send snprintf @@ -382,6 +386,7 @@ This is the full list of functions generally banned. sscanf stat strcat + strdup strerror strncat strncpy diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 85faa875e0..cdd5587ec8 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -300,8 +300,6 @@ LIB_HFILES = \ curl_ldap.h \ curl_md4.h \ curl_md5.h \ - curl_mem_undef.h \ - curl_memory.h \ curl_memrchr.h \ curl_ntlm_core.h \ curl_printf.h \ @@ -353,7 +351,6 @@ LIB_HFILES = \ imap.h \ llist.h \ macos.h \ - memdebug.h \ mime.h \ mqtt.h \ multihandle.h \ diff --git a/lib/altsvc.c b/lib/altsvc.c index c05dff04e2..84f6c1b445 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -42,10 +42,6 @@ #include "curlx/strparse.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define MAX_ALTSVC_LINE 4095 #define MAX_ALTSVC_DATELEN 256 #define MAX_ALTSVC_HOSTLEN 2048 @@ -71,9 +67,9 @@ const char *Curl_alpnid2str(enum alpnid id) static void altsvc_free(struct altsvc *as) { - free(as->src.host); - free(as->dst.host); - free(as); + curlx_free(as->src.host); + curlx_free(as->dst.host); + curlx_free(as); } static struct altsvc *altsvc_createid(const char *srchost, @@ -85,7 +81,7 @@ static struct altsvc *altsvc_createid(const char *srchost, size_t srcport, size_t dstport) { - struct altsvc *as = calloc(1, sizeof(struct altsvc)); + struct altsvc *as = curlx_calloc(1, sizeof(struct altsvc)); if(!as) return NULL; DEBUGASSERT(hlen); @@ -219,8 +215,8 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file) /* we need a private copy of the filename so that the altsvc cache file name survives an easy handle reset */ - free(asi->filename); - asi->filename = strdup(file); + curlx_free(asi->filename); + asi->filename = curlx_strdup(file); if(!asi->filename) return CURLE_OUT_OF_MEMORY; @@ -299,7 +295,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp) */ struct altsvcinfo *Curl_altsvc_init(void) { - struct altsvcinfo *asi = calloc(1, sizeof(struct altsvcinfo)); + struct altsvcinfo *asi = curlx_calloc(1, sizeof(struct altsvcinfo)); if(!asi) return NULL; Curl_llist_init(&asi->list, NULL); @@ -350,8 +346,8 @@ void Curl_altsvc_cleanup(struct altsvcinfo **altsvcp) n = Curl_node_next(e); altsvc_free(as); } - free(altsvc->filename); - free(altsvc); + curlx_free(altsvc->filename); + curlx_free(altsvc); *altsvcp = NULL; /* clear the pointer */ } } @@ -399,7 +395,7 @@ CURLcode Curl_altsvc_save(struct Curl_easy *data, if(result && tempstore) unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); return result; } diff --git a/lib/amigaos.c b/lib/amigaos.c index e51236d126..e4b678d541 100644 --- a/lib/amigaos.c +++ b/lib/amigaos.c @@ -42,10 +42,6 @@ # endif #endif -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef HAVE_PROTO_BSDSOCKET_H #ifdef __amigaos4__ @@ -135,7 +131,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, LONG h_errnop = 0; struct hostent *buf; - buf = calloc(1, CURL_HOSTENT_SIZE); + buf = curlx_calloc(1, CURL_HOSTENT_SIZE); if(buf) { h = gethostbyname_r((STRPTR)hostname, buf, (char *)buf + sizeof(struct hostent), @@ -144,7 +140,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, if(h) { ai = Curl_he2ai(h, port); } - free(buf); + curlx_free(buf); } } else { diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 1bc0f3247b..e3ba512b77 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -104,10 +104,6 @@ #define HTTPSRR_WORKS #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CARES_TIMEOUT_PER_ATTEMPT 2000 static int ares_ver = 0; @@ -633,7 +629,7 @@ async_ares_node2addr(struct ares_addrinfo_node *node) if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct Curl_addrinfo) + ss_size); + ca = curlx_malloc(sizeof(struct Curl_addrinfo) + ss_size); if(!ca) { error = EAI_MEMORY; break; @@ -736,7 +732,7 @@ CURLcode Curl_async_getaddrinfo(struct Curl_easy *data, const char *hostname, data->state.async.dns = NULL; /* clear */ data->state.async.port = port; data->state.async.ip_version = ip_version; - data->state.async.hostname = strdup(hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) return CURLE_OUT_OF_MEMORY; #ifdef USE_HTTPSRR diff --git a/lib/asyn-base.c b/lib/asyn-base.c index d7e8e7d15b..6338a3fc6e 100644 --- a/lib/asyn-base.c +++ b/lib/asyn-base.c @@ -53,9 +53,6 @@ #include "select.h" #include "curl_share.h" #include "url.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" /*********************************************************************** * Only for builds using asynchronous name resolves diff --git a/lib/asyn-thrdd.c b/lib/asyn-thrdd.c index 71e31e6d0d..6c2e02fd18 100644 --- a/lib/asyn-thrdd.c +++ b/lib/asyn-thrdd.c @@ -72,10 +72,6 @@ #endif #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Curl_async_global_init() @@ -136,7 +132,7 @@ static void addr_ctx_unlink(struct async_thrdd_addr_ctx **paddr_ctx, if(destroy) { Curl_mutex_destroy(&addr_ctx->mutx); - free(addr_ctx->hostname); + curlx_free(addr_ctx->hostname); if(addr_ctx->res) Curl_freeaddrinfo(addr_ctx->res); #ifndef CURL_DISABLE_SOCKETPAIR @@ -145,7 +141,7 @@ static void addr_ctx_unlink(struct async_thrdd_addr_ctx **paddr_ctx, #endif wakeup_close(addr_ctx->sock_pair[0]); #endif - free(addr_ctx); + curlx_free(addr_ctx); } *paddr_ctx = NULL; } @@ -156,7 +152,7 @@ addr_ctx_create(struct Curl_easy *data, const char *hostname, int port, const struct addrinfo *hints) { - struct async_thrdd_addr_ctx *addr_ctx = calloc(1, sizeof(*addr_ctx)); + struct async_thrdd_addr_ctx *addr_ctx = curlx_calloc(1, sizeof(*addr_ctx)); if(!addr_ctx) return NULL; @@ -186,7 +182,7 @@ addr_ctx_create(struct Curl_easy *data, /* Copying hostname string because original can be destroyed by parent * thread during gethostbyname execution. */ - addr_ctx->hostname = strdup(hostname); + addr_ctx->hostname = curlx_strdup(hostname); if(!addr_ctx->hostname) goto err_exit; @@ -376,7 +372,7 @@ static CURLcode async_rr_start(struct Curl_easy *data, int port) status = ares_init_options(&thrdd->rr.channel, NULL, 0); if(status != ARES_SUCCESS) { thrdd->rr.channel = NULL; - free(rrname); + curlx_free(rrname); return CURLE_FAILED_INIT; } #ifdef CURLDEBUG @@ -384,7 +380,7 @@ static CURLcode async_rr_start(struct Curl_easy *data, int port) const char *servers = getenv("CURL_DNS_SERVER"); status = ares_set_servers_ports_csv(thrdd->rr.channel, servers); if(status) { - free(rrname); + curlx_free(rrname); return CURLE_FAILED_INIT; } } @@ -435,8 +431,8 @@ static bool async_thrdd_init(struct Curl_easy *data, data->state.async.done = FALSE; data->state.async.port = port; data->state.async.ip_version = ip_version; - free(data->state.async.hostname); - data->state.async.hostname = strdup(hostname); + curlx_free(data->state.async.hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) goto err_exit; diff --git a/lib/bufq.c b/lib/bufq.c index d38b78c6d5..5a77fc52d4 100644 --- a/lib/bufq.c +++ b/lib/bufq.c @@ -25,10 +25,6 @@ #include "curl_setup.h" #include "bufq.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static bool chunk_is_empty(const struct buf_chunk *chunk) { return chunk->r_offset >= chunk->w_offset; @@ -143,7 +139,7 @@ static void chunk_list_free(struct buf_chunk **anchor) while(*anchor) { chunk = *anchor; *anchor = chunk->next; - free(chunk); + curlx_free(chunk); } } @@ -178,7 +174,7 @@ static CURLcode bufcp_take(struct bufc_pool *pool, return CURLE_OUT_OF_MEMORY; } - chunk = calloc(1, sizeof(*chunk) + pool->chunk_size); + chunk = curlx_calloc(1, sizeof(*chunk) + pool->chunk_size); if(!chunk) { *pchunk = NULL; return CURLE_OUT_OF_MEMORY; @@ -192,7 +188,7 @@ static void bufcp_put(struct bufc_pool *pool, struct buf_chunk *chunk) { if(pool->spare_count >= pool->spare_max) { - free(chunk); + curlx_free(chunk); } else { chunk_reset(chunk); @@ -311,7 +307,7 @@ static struct buf_chunk *get_spare(struct bufq *q) return NULL; } - chunk = calloc(1, sizeof(*chunk) + q->chunk_size); + chunk = curlx_calloc(1, sizeof(*chunk) + q->chunk_size); if(!chunk) return NULL; chunk->dlen = q->chunk_size; @@ -338,7 +334,7 @@ static void prune_head(struct bufq *q) /* SOFT_LIMIT allowed us more than max. free spares until * we are at max again. Or free them if we are configured * to not use spares. */ - free(chunk); + curlx_free(chunk); --q->chunk_count; } else { diff --git a/lib/bufref.c b/lib/bufref.c index ac0612071d..d5181a5da6 100644 --- a/lib/bufref.c +++ b/lib/bufref.c @@ -27,9 +27,6 @@ #include "bufref.h" #include "strdup.h" -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define SIGNATURE 0x5c48e9b2 /* Random pattern. */ #endif diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index 417b4df67e..84ba3d6193 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -46,10 +46,6 @@ #include "multiif.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { H1_TUNNEL_INIT, /* init/default/no tunnel state */ @@ -116,7 +112,7 @@ static CURLcode tunnel_init(struct Curl_cfilter *cf, return CURLE_UNSUPPORTED_PROTOCOL; } - ts = calloc(1, sizeof(*ts)); + ts = curlx_calloc(1, sizeof(*ts)); if(!ts) return CURLE_OUT_OF_MEMORY; @@ -194,7 +190,7 @@ static void tunnel_free(struct Curl_cfilter *cf, curlx_dyn_free(&ts->rcvbuf); curlx_dyn_free(&ts->request_data); Curl_httpchunk_free(data, &ts->ch); - free(ts); + curlx_free(ts); cf->ctx = NULL; } } @@ -215,7 +211,7 @@ static CURLcode start_CONNECT(struct Curl_cfilter *cf, /* This only happens if we have looped here due to authentication reasons, and we do not really use the newly cloned URL here - then. Just free() it. */ + then. Just free it. */ Curl_safefree(data->req.newurl); result = Curl_http_proxy_create_CONNECT(&req, cf, data, 1); @@ -298,7 +294,7 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, CURL_TRC_CF(data, cf, "CONNECT: fwd auth header '%s'", header); result = Curl_http_input_auth(data, proxy, auth); - free(auth); + curlx_free(auth); if(result) return result; diff --git a/lib/cf-h2-proxy.c b/lib/cf-h2-proxy.c index fca916a2c2..7066db3b4c 100644 --- a/lib/cf-h2-proxy.c +++ b/lib/cf-h2-proxy.c @@ -45,10 +45,6 @@ #include "curlx/warnless.h" #include "cf-h2-proxy.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define PROXY_H2_CHUNK_SIZE (16*1024) #define PROXY_HTTP2_HUGE_WINDOW_SIZE (100 * 1024 * 1024) @@ -209,7 +205,7 @@ static void cf_h2_proxy_ctx_free(struct cf_h2_proxy_ctx *ctx) { if(ctx) { cf_h2_proxy_ctx_clear(ctx); - free(ctx); + curlx_free(ctx); } } @@ -919,7 +915,7 @@ static CURLcode proxy_h2_submit(int32_t *pstream_id, result = CURLE_OK; out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); *pstream_id = stream_id; return result; @@ -1594,7 +1590,7 @@ CURLcode Curl_cf_h2_proxy_insert_after(struct Curl_cfilter *cf, CURLcode result = CURLE_OUT_OF_MEMORY; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; diff --git a/lib/cf-haproxy.c b/lib/cf-haproxy.c index 8912604504..a1793c0071 100644 --- a/lib/cf-haproxy.c +++ b/lib/cf-haproxy.c @@ -34,10 +34,6 @@ #include "multiif.h" #include "select.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { HAPROXY_INIT, /* init/default/no tunnel state */ @@ -61,7 +57,7 @@ static void cf_haproxy_ctx_free(struct cf_haproxy_ctx *ctx) { if(ctx) { curlx_dyn_free(&ctx->data_out); - free(ctx); + curlx_free(ctx); } } @@ -217,7 +213,7 @@ static CURLcode cf_haproxy_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/cf-https-connect.c b/lib/cf-https-connect.c index 5491d7968d..ad815a0fe7 100644 --- a/lib/cf-https-connect.c +++ b/lib/cf-https-connect.c @@ -38,10 +38,6 @@ #include "select.h" #include "vquic/vquic.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { CF_HC_INIT, CF_HC_CONNECT, @@ -588,7 +584,7 @@ static CURLcode cf_hc_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OK; size_t i; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -618,7 +614,7 @@ static CURLcode cf_hc_create(struct Curl_cfilter **pcf, out: *pcf = result ? NULL : cf; - free(ctx); + curlx_free(ctx); return result; } diff --git a/lib/cf-ip-happy.c b/lib/cf-ip-happy.c index eb62cd4c73..8901db02c2 100644 --- a/lib/cf-ip-happy.c +++ b/lib/cf-ip-happy.c @@ -60,10 +60,6 @@ #include "select.h" #include "vquic/vquic.h" /* for quic cfilters */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - struct transport_provider { uint8_t transport; @@ -186,7 +182,7 @@ static void cf_ip_attempt_free(struct cf_ip_attempt *a, if(a) { if(a->cf) Curl_conn_cf_discard_chain(&a->cf, data); - free(a); + curlx_free(a); } } @@ -203,7 +199,7 @@ static CURLcode cf_ip_attempt_new(struct cf_ip_attempt **pa, CURLcode result = CURLE_OK; *pa = NULL; - a = calloc(1, sizeof(*a)); + a = curlx_calloc(1, sizeof(*a)); if(!a) return CURLE_OUT_OF_MEMORY; @@ -941,7 +937,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, (void)data; (void)conn; *pcf = NULL; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -954,7 +950,7 @@ static CURLcode cf_ip_happy_create(struct Curl_cfilter **pcf, out: if(result) { Curl_safefree(*pcf); - free(ctx); + curlx_free(ctx); } return result; } diff --git a/lib/cf-socket.c b/lib/cf-socket.c index 6e5333602c..3172aee5b9 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -82,10 +82,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(USE_IPV6) && defined(IPV6_V6ONLY) && defined(_WIN32) /* It makes support for IPv4-mapped IPv6 addresses. @@ -555,7 +551,7 @@ CURLcode Curl_parse_interface(const char *input, ++host_part; *host = Curl_memdup0(host_part, len - (host_part - input)); if(!*host) { - free(*iface); + curlx_free(*iface); *iface = NULL; return CURLE_OUT_OF_MEMORY; } @@ -1026,7 +1022,7 @@ static void cf_socket_destroy(struct Curl_cfilter *cf, struct Curl_easy *data) cf_socket_close(cf, data); CURL_TRC_CF(data, cf, "destroy"); - free(ctx); + curlx_free(ctx); cf->ctx = NULL; } @@ -1758,7 +1754,7 @@ CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf, goto out; } - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1920,7 +1916,7 @@ CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf, (void)data; (void)conn; DEBUGASSERT(transport == TRNSPRT_UDP || transport == TRNSPRT_QUIC); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1974,7 +1970,7 @@ CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf, (void)data; (void)conn; DEBUGASSERT(transport == TRNSPRT_UNIX); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -2199,7 +2195,7 @@ CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data, Curl_conn_cf_discard_all(data, conn, sockindex); DEBUGASSERT(conn->sock[sockindex] == CURL_SOCKET_BAD); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/cfilters.c b/lib/cfilters.c index 7cb10f3928..7d1f0c3d9e 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -37,10 +37,6 @@ #include "curlx/warnless.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void cf_cntrl_update_info(struct Curl_easy *data, struct connectdata *conn); @@ -143,7 +139,7 @@ void Curl_conn_cf_discard_chain(struct Curl_cfilter **pcf, */ cf->next = NULL; cf->cft->destroy(cf, data); - free(cf); + curlx_free(cf); cf = cfn; } } @@ -332,7 +328,7 @@ CURLcode Curl_cf_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OUT_OF_MEMORY; DEBUGASSERT(cft); - cf = calloc(1, sizeof(*cf)); + cf = curlx_calloc(1, sizeof(*cf)); if(!cf) goto out; diff --git a/lib/conncache.c b/lib/conncache.c index 9d3b69bec3..7f38a18757 100644 --- a/lib/conncache.c +++ b/lib/conncache.c @@ -45,10 +45,6 @@ #include "curlx/strparse.h" #include "uint-table.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CPOOL_IS_LOCKED(c) ((c) && (c)->locked) @@ -92,7 +88,7 @@ static struct cpool_bundle *cpool_bundle_create(const char *dest) struct cpool_bundle *bundle; size_t dest_len = strlen(dest) + 1; - bundle = calloc(1, sizeof(*bundle) + dest_len - 1); + bundle = curlx_calloc(1, sizeof(*bundle) + dest_len - 1); if(!bundle) return NULL; Curl_llist_init(&bundle->conns, NULL); @@ -104,7 +100,7 @@ static struct cpool_bundle *cpool_bundle_create(const char *dest) static void cpool_bundle_destroy(struct cpool_bundle *bundle) { DEBUGASSERT(!Curl_llist_count(&bundle->conns)); - free(bundle); + curlx_free(bundle); } /* Add a connection to a bundle */ diff --git a/lib/connect.c b/lib/connect.c index e29c2f51bc..72a27fae1c 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -76,10 +76,6 @@ #include "http_proxy.h" #include "socks.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if !defined(CURL_DISABLE_ALTSVC) || defined(USE_HTTPSRR) enum alpnid Curl_alpn2alpnid(const unsigned char *name, size_t len) @@ -527,7 +523,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, CURLcode result = CURLE_OK; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -544,7 +540,7 @@ static CURLcode cf_setup_create(struct Curl_cfilter **pcf, out: *pcf = result ? NULL : cf; if(ctx) { - free(ctx); + curlx_free(ctx); } return result; } diff --git a/lib/content_encoding.c b/lib/content_encoding.c index f128f7565f..84ed86c1df 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -52,10 +52,6 @@ #include "http.h" #include "content_encoding.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define CONTENT_ENCODING_DEFAULT "identity" #ifndef CURL_DISABLE_HTTP @@ -95,15 +91,15 @@ static voidpf zalloc_cb(voidpf opaque, unsigned int items, unsigned int size) { (void)opaque; - /* not a typo, keep it calloc() */ - return (voidpf) calloc(items, size); + /* not a typo, keep it curlx_calloc() */ + return (voidpf)curlx_calloc(items, size); } static void zfree_cb(voidpf opaque, voidpf ptr) { (void)opaque; - free(ptr); + curlx_free(ptr); } static CURLcode diff --git a/lib/cookie.c b/lib/cookie.c index 6099c6ea56..250c7390ce 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -42,10 +42,6 @@ #include "llist.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void strstore(char **str, const char *newstr, size_t len); /* number of seconds in 400 days */ @@ -70,12 +66,12 @@ static void cap_expires(time_t now, struct Cookie *co) static void freecookie(struct Cookie *co) { - free(co->domain); - free(co->path); - free(co->spath); - free(co->name); - free(co->value); - free(co); + curlx_free(co->domain); + curlx_free(co->path); + curlx_free(co->spath); + curlx_free(co->name); + curlx_free(co->value); + curlx_free(co); } static bool cookie_tailmatch(const char *cookie_domain, @@ -246,7 +242,7 @@ static char *sanitize_cookie_path(const char *cookie_path) /* RFC6265 5.2.4 The Path Attribute */ if(cookie_path[0] != '/') /* Let cookie-path be the default-path. */ - return strdup("/"); + return curlx_strdup("/"); /* remove trailing slash when path is non-empty */ /* convert /hoge/ to /hoge */ @@ -268,7 +264,7 @@ static char *sanitize_cookie_path(const char *cookie_path) static void strstore(char **str, const char *newstr, size_t len) { DEBUGASSERT(str); - free(*str); + curlx_free(*str); if(!len) { len++; newstr = ""; @@ -506,7 +502,7 @@ parse_cookie_header(struct Curl_easy *data, strstore(&co->path, curlx_str(&val), curlx_strlen(&val)); if(!co->path) return CURLE_OUT_OF_MEMORY; - free(co->spath); /* if this is set again */ + curlx_free(co->spath); /* if this is set again */ co->spath = sanitize_cookie_path(co->path); if(!co->spath) return CURLE_OUT_OF_MEMORY; @@ -631,7 +627,7 @@ parse_cookie_header(struct Curl_easy *data, if(!co->domain && domain) { /* no domain was given in the header line, set the default */ - co->domain = strdup(domain); + co->domain = curlx_strdup(domain); if(!co->domain) return CURLE_OUT_OF_MEMORY; } @@ -739,10 +735,10 @@ parse_netscape(struct Cookie *co, break; } /* this does not look like a path, make one up! */ - co->path = strdup("/"); + co->path = curlx_strdup("/"); if(!co->path) return CURLE_OUT_OF_MEMORY; - co->spath = strdup("/"); + co->spath = curlx_strdup("/"); if(!co->spath) return CURLE_OUT_OF_MEMORY; fields++; /* add a field and fall down to secure */ @@ -781,7 +777,7 @@ parse_netscape(struct Cookie *co, } if(fields == 6) { /* we got a cookie with blank contents, fix it */ - co->value = strdup(""); + co->value = curlx_strdup(""); if(!co->value) return CURLE_OUT_OF_MEMORY; else @@ -981,7 +977,7 @@ Curl_cookie_add(struct Curl_easy *data, return CURLE_OK; /* silently ignore */ /* First, alloc and init a new struct for it */ - co = calloc(1, sizeof(struct Cookie)); + co = curlx_calloc(1, sizeof(struct Cookie)); if(!co) return CURLE_OUT_OF_MEMORY; /* bail out if we are this low on memory */ @@ -1081,7 +1077,7 @@ fail: struct CookieInfo *Curl_cookie_init(void) { int i; - struct CookieInfo *ci = calloc(1, sizeof(struct CookieInfo)); + struct CookieInfo *ci = curlx_calloc(1, sizeof(struct CookieInfo)); if(!ci) return NULL; @@ -1343,7 +1339,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data, size_t i; /* alloc an array and store all cookie pointers */ - array = malloc(sizeof(struct Cookie *) * matches); + array = curlx_malloc(sizeof(struct Cookie *) * matches); if(!array) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -1363,7 +1359,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data, for(i = 0; i < matches; i++) Curl_llist_append(list, array[i], &array[i]->getnode); - free(array); /* remove the temporary data again */ + curlx_free(array); /* remove the temporary data again */ } *okay = TRUE; @@ -1435,7 +1431,7 @@ void Curl_cookie_cleanup(struct CookieInfo *ci) { if(ci) { Curl_cookie_clearall(ci); - free(ci); /* free the base struct as well */ + curlx_free(ci); /* free the base struct as well */ } } @@ -1518,7 +1514,7 @@ static CURLcode cookie_output(struct Curl_easy *data, struct Cookie **array; struct Curl_llist_node *n; - array = calloc(1, sizeof(struct Cookie *) * ci->numcookies); + array = curlx_calloc(1, sizeof(struct Cookie *) * ci->numcookies); if(!array) { error = CURLE_OUT_OF_MEMORY; goto error; @@ -1540,15 +1536,15 @@ static CURLcode cookie_output(struct Curl_easy *data, for(i = 0; i < nvalid; i++) { char *format_ptr = get_netscape_format(array[i]); if(!format_ptr) { - free(array); + curlx_free(array); error = CURLE_OUT_OF_MEMORY; goto error; } curl_mfprintf(out, "%s\n", format_ptr); - free(format_ptr); + curlx_free(format_ptr); } - free(array); + curlx_free(array); } if(!use_stdout) { @@ -1565,7 +1561,7 @@ static CURLcode cookie_output(struct Curl_easy *data, * no need to inspect the error, any error case should have jumped into the * error block below. */ - free(tempstore); + curlx_free(tempstore); return CURLE_OK; error: @@ -1573,7 +1569,7 @@ error: curlx_fclose(out); if(tempstore) { unlink(tempstore); - free(tempstore); + curlx_free(tempstore); } return error; } @@ -1605,7 +1601,7 @@ static struct curl_slist *cookie_list(struct Curl_easy *data) } beg = Curl_slist_append_nodup(list, line); if(!beg) { - free(line); + curlx_free(line); curl_slist_free_all(list); return NULL; } diff --git a/lib/cshutdn.c b/lib/cshutdn.c index e039d02762..0a4ab41647 100644 --- a/lib/cshutdn.c +++ b/lib/cshutdn.c @@ -42,10 +42,6 @@ #include "select.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void cshutdn_run_conn_handler(struct Curl_easy *data, struct connectdata *conn) diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c index cd9b52feba..67c2f4177d 100644 --- a/lib/curl_addrinfo.c +++ b/lib/curl_addrinfo.c @@ -54,10 +54,6 @@ #include "curlx/inet_pton.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Curl_freeaddrinfo() * @@ -83,7 +79,7 @@ Curl_freeaddrinfo(struct Curl_addrinfo *cahead) for(ca = cahead; ca; ca = canext) { canext = ca->ai_next; - free(ca); + curlx_free(ca); } } @@ -146,7 +142,7 @@ Curl_getaddrinfo_ex(const char *nodename, if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen); + ca = curlx_malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen); if(!ca) { error = EAI_MEMORY; break; @@ -285,7 +281,7 @@ Curl_he2ai(const struct hostent *he, int port) ss_size = sizeof(struct sockaddr_in); /* allocate memory to hold the struct, the address and the name */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen); if(!ai) { result = CURLE_OUT_OF_MEMORY; break; @@ -382,7 +378,7 @@ ip2addr(struct Curl_addrinfo **addrp, return CURLE_BAD_FUNCTION_ARGUMENT; /* allocate memory to hold the struct, the address and the name */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); if(!ai) return CURLE_OUT_OF_MEMORY; /* put the address after the struct */ @@ -471,7 +467,8 @@ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, *longpath = FALSE; - ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un)); + ai = curlx_calloc(1, + sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un)); if(!ai) return NULL; ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); @@ -482,7 +479,7 @@ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, /* sun_path must be able to store the null-terminated path */ path_len = strlen(path) + 1; if(path_len > sizeof(sa_un->sun_path)) { - free(ai); + curlx_free(ai); *longpath = TRUE; return NULL; } diff --git a/lib/curl_fnmatch.c b/lib/curl_fnmatch.c index 3148c472e2..918be89d4b 100644 --- a/lib/curl_fnmatch.c +++ b/lib/curl_fnmatch.c @@ -27,10 +27,6 @@ #include #include "curl_fnmatch.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_FNMATCH diff --git a/lib/curl_fopen.c b/lib/curl_fopen.c index f16b3d6cde..cccf849acb 100644 --- a/lib/curl_fopen.c +++ b/lib/curl_fopen.c @@ -31,10 +31,6 @@ #include "rand.h" #include "curl_fopen.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* The dirslash() function breaks a null-terminated pathname string into directory and filename components then returns the directory component up @@ -120,7 +116,7 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename, /* The temp filename should not end up too long for the target file system */ tempstore = curl_maprintf("%s%s.tmp", dir, randbuf); - free(dir); + curlx_free(dir); } if(!tempstore) { @@ -156,7 +152,7 @@ fail: unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); return result; } diff --git a/lib/curl_get_line.c b/lib/curl_get_line.c index d5ab7b8427..ea31eb182f 100644 --- a/lib/curl_get_line.c +++ b/lib/curl_get_line.c @@ -28,9 +28,6 @@ !defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC) #include "curl_get_line.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" #define appendnl(b) \ curlx_dyn_addn(buf, "\n", 1) diff --git a/lib/curl_gssapi.c b/lib/curl_gssapi.c index 947bb9c006..edd555db79 100644 --- a/lib/curl_gssapi.c +++ b/lib/curl_gssapi.c @@ -31,10 +31,8 @@ #ifdef DEBUGBUILD #if defined(HAVE_GSSGNU) || !defined(_WIN32) -/* To avoid memdebug macro replacement, wrap the name in parentheses to call - the original version. It is freed via the GSS API gss_release_buffer(). */ -#define Curl_gss_alloc (malloc) -#define Curl_gss_free (free) +#define Curl_gss_alloc malloc /* freed via the GSS API gss_release_buffer() */ +#define Curl_gss_free free /* pair of the above */ #define CURL_GSS_STUB /* For correctness this would be required for all platforms, not only Windows, but, as of v1.22.1, MIT Kerberos uses a special allocator only for Windows, @@ -51,10 +49,6 @@ #endif #endif /* DEBUGBUILD */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef __GNUC__ #define CURL_ALIGN8 __attribute__((aligned(8))) #else @@ -208,7 +202,7 @@ stub_gss_init_sec_context(OM_uint32 *min, return GSS_S_FAILURE; } - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; @@ -225,7 +219,7 @@ stub_gss_init_sec_context(OM_uint32 *min, else if(ctx->have_ntlm) ctx->sent = STUB_GSS_NTLM1; else { - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MECH; return GSS_S_FAILURE; } @@ -236,7 +230,7 @@ stub_gss_init_sec_context(OM_uint32 *min, token = Curl_gss_alloc(length); if(!token) { - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -250,14 +244,14 @@ stub_gss_init_sec_context(OM_uint32 *min, &target_desc, &name_type); if(GSS_ERROR(major_status)) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } if(strlen(creds) + target_desc.length + 5 >= sizeof(ctx->creds)) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -273,7 +267,7 @@ stub_gss_init_sec_context(OM_uint32 *min, if(used >= length) { Curl_gss_free(token); - free(ctx); + curlx_free(ctx); *min = STUB_GSS_NO_MEMORY; return GSS_S_FAILURE; } @@ -308,7 +302,7 @@ stub_gss_delete_sec_context(OM_uint32 *min, return GSS_S_FAILURE; } - free(*context); + curlx_free(*context); *context = NULL; *min = 0; diff --git a/lib/curl_mem_undef.h b/lib/curl_mem_undef.h deleted file mode 100644 index 2be114cbd5..0000000000 --- a/lib/curl_mem_undef.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , 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 - * - ***************************************************************************/ - -/* Unset redefined system symbols. */ - -#undef strdup -#undef malloc -#undef calloc -#undef realloc -#undef free -#ifdef _WIN32 -#undef Curl_tcsdup -#endif - -#undef HEADER_CURL_MEMORY_H -#undef HEADER_CURL_MEMDEBUG_H diff --git a/lib/curl_memory.h b/lib/curl_memory.h deleted file mode 100644 index 7793bb63a3..0000000000 --- a/lib/curl_memory.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef HEADER_CURL_MEMORY_H -#define HEADER_CURL_MEMORY_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , 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 - * - ***************************************************************************/ - -/* - * Nasty internal details ahead... - * - * File curl_memory.h must be included by _all_ *.c source files - * that use memory related functions strdup, malloc, calloc, realloc - * or free, and given source file is used to build libcurl library. - * It should be included immediately before memdebug.h as the last files - * included to avoid undesired interaction with other memory function - * headers in dependent libraries. - * - * There is nearly no exception to above rule. All libcurl source - * files in 'lib' subdirectory as well as those living deep inside - * 'packages' subdirectories and linked together in order to build - * libcurl library shall follow it. - * - * File lib/strdup.c is an exception, given that it provides a strdup - * clone implementation while using malloc. Extra care needed inside - * this one. - * - * The need for curl_memory.h inclusion is due to libcurl's feature - * of allowing library user to provide memory replacement functions, - * memory callbacks, at runtime with curl_global_init_mem() - * - * Any *.c source file used to build libcurl library that does not - * include curl_memory.h and uses any memory function of the five - * mentioned above will compile without any indication, but it will - * trigger weird memory related issues at runtime. - * - */ - -#ifndef CURLDEBUG - -/* - * libcurl's 'memory tracking' system defines strdup, malloc, calloc, - * realloc and free, along with others, in memdebug.h in a different - * way although still using memory callbacks forward declared above. - * When using the 'memory tracking' system (CURLDEBUG defined) we do - * not define here the five memory functions given that definitions - * from memdebug.h are the ones that shall be used. - */ - -#undef strdup -#define strdup(ptr) Curl_cstrdup(ptr) -#undef malloc -#define malloc(size) Curl_cmalloc(size) -#undef calloc -#define calloc(nbelem,size) Curl_ccalloc(nbelem, size) -#undef realloc -#define realloc(ptr,size) Curl_crealloc(ptr, size) -#undef free -#define free(ptr) Curl_cfree(ptr) - -#ifdef _WIN32 -#undef Curl_tcsdup -#ifdef UNICODE -#define Curl_tcsdup(ptr) Curl_wcsdup(ptr) -#else -#define Curl_tcsdup(ptr) Curl_cstrdup(ptr) -#endif -#endif /* _WIN32 */ - -#endif /* CURLDEBUG */ -#endif /* HEADER_CURL_MEMORY_H */ diff --git a/lib/curl_memrchr.c b/lib/curl_memrchr.c index 5b6a39c022..8146458407 100644 --- a/lib/curl_memrchr.c +++ b/lib/curl_memrchr.c @@ -27,10 +27,6 @@ #include #include "curl_memrchr.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_MEMRCHR /* diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c index d013929d4d..f2c8c2d2a6 100644 --- a/lib/curl_ntlm_core.c +++ b/lib/curl_ntlm_core.c @@ -122,10 +122,6 @@ #include "curl_endian.h" #include "curl_md4.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_CURL_DES_SET_ODD_PARITY /* * curl_des_set_odd_parity() @@ -437,7 +433,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password, CURLcode result; if(len > SIZE_MAX/2) /* avoid integer overflow */ return CURLE_OUT_OF_MEMORY; - pw = len ? malloc(len * 2) : (unsigned char *)strdup(""); + pw = len ? curlx_malloc(len * 2) : (unsigned char *)curlx_strdup(""); if(!pw) return CURLE_OUT_OF_MEMORY; @@ -448,7 +444,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password, if(!result) memset(ntbuffer + 16, 0, 21 - 16); - free(pw); + curlx_free(pw); return result; } @@ -525,7 +521,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, return CURLE_OUT_OF_MEMORY; identity_len = (userlen + domlen) * 2; - identity = malloc(identity_len + 1); + identity = curlx_malloc(identity_len + 1); if(!identity) return CURLE_OUT_OF_MEMORY; @@ -535,7 +531,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, result = Curl_hmacit(&Curl_HMAC_MD5, ntlmhash, 16, identity, identity_len, ntlmv2hash); - free(identity); + curlx_free(identity); return result; } @@ -598,7 +594,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, len = HMAC_MD5_LENGTH + NTLMv2_BLOB_LEN; /* Allocate the response */ - ptr = calloc(1, len); + ptr = curlx_calloc(1, len); if(!ptr) return CURLE_OUT_OF_MEMORY; @@ -622,7 +618,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, result = Curl_hmacit(&Curl_HMAC_MD5, ntlmv2hash, HMAC_MD5_LENGTH, ptr + 8, NTLMv2_BLOB_LEN + 8, hmac_output); if(result) { - free(ptr); + curlx_free(ptr); return result; } diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c index 2d2daf4148..351c9f494c 100644 --- a/lib/curl_rtmp.c +++ b/lib/curl_rtmp.c @@ -37,10 +37,6 @@ #include #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(_WIN32) && !defined(USE_LWIPSOCK) #define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e) #define SET_RCVTIMEO(tv,s) int tv = s*1000 diff --git a/lib/curl_sasl.c b/lib/curl_sasl.c index f6ec668bfd..aef47dc016 100644 --- a/lib/curl_sasl.c +++ b/lib/curl_sasl.c @@ -51,10 +51,6 @@ #include "curlx/warnless.h" #include "sendf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Supported mechanisms */ static const struct { const char *name; /* Name */ diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 6236a71539..6acac0d17a 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -941,7 +941,7 @@ extern curl_calloc_callback Curl_ccalloc; * This macro also assigns NULL to given pointer when free'd. */ #define Curl_safefree(ptr) \ - do { free(ptr); (ptr) = NULL;} while(0) + do { curlx_free(ptr); (ptr) = NULL;} while(0) #include /* for CURL_EXTERN, mprintf.h */ @@ -1077,6 +1077,56 @@ CURL_EXTERN ALLOC_FUNC #endif /* CURLDEBUG */ +/* Allocator macros */ + +#ifdef CURLDEBUG + +#define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) +#define curlx_malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) +#define curlx_calloc(nbelem,size) \ + curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) +#define curlx_realloc(ptr,size) \ + curl_dbg_realloc(ptr, size, __LINE__, __FILE__) +#define curlx_free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__) + +#ifdef _WIN32 +#ifdef UNICODE +#define curlx_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__) +#else +#define curlx_tcsdup(ptr) curlx_strdup(ptr) +#endif +#endif /* _WIN32 */ + +#else /* !CURLDEBUG */ + +#ifdef BUILDING_LIBCURL +#define curlx_strdup(ptr) Curl_cstrdup(ptr) +#define curlx_malloc(size) Curl_cmalloc(size) +#define curlx_calloc(nbelem,size) Curl_ccalloc(nbelem, size) +#define curlx_realloc(ptr,size) Curl_crealloc(ptr, size) +#define curlx_free(ptr) Curl_cfree(ptr) +#else /* !BUILDING_LIBCURL */ +#ifdef _WIN32 +#define curlx_strdup(ptr) _strdup(ptr) +#else +#define curlx_strdup(ptr) strdup(ptr) +#endif +#define curlx_malloc(size) malloc(size) +#define curlx_calloc(nbelem,size) calloc(nbelem, size) +#define curlx_realloc(ptr,size) realloc(ptr, size) +#define curlx_free(ptr) free(ptr) +#endif /* BUILDING_LIBCURL */ + +#ifdef _WIN32 +#ifdef UNICODE +#define curlx_tcsdup(ptr) Curl_wcsdup(ptr) +#else +#define curlx_tcsdup(ptr) curlx_strdup(ptr) +#endif +#endif /* _WIN32 */ + +#endif /* CURLDEBUG */ + /* Some versions of the Android NDK is missing the declaration */ #if defined(HAVE_GETPWUID_R) && \ defined(__ANDROID_API__) && (__ANDROID_API__ < 21) @@ -1167,5 +1217,3 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, #endif #endif /* HEADER_CURL_SETUP_H */ - -#include "curl_mem_undef.h" diff --git a/lib/curl_share.c b/lib/curl_share.c index b65d16c628..c6b5126704 100644 --- a/lib/curl_share.c +++ b/lib/curl_share.c @@ -34,21 +34,17 @@ #include "hsts.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - CURLSH * curl_share_init(void) { - struct Curl_share *share = calloc(1, sizeof(struct Curl_share)); + struct Curl_share *share = curlx_calloc(1, sizeof(struct Curl_share)); if(share) { share->magic = CURL_GOOD_SHARE; share->specifier |= (1 << CURL_LOCK_DATA_SHARE); Curl_dnscache_init(&share->dnscache, 23); share->admin = curl_easy_init(); if(!share->admin) { - free(share); + curlx_free(share); return NULL; } /* admin handles have mid 0 */ @@ -272,7 +268,7 @@ curl_share_cleanup(CURLSH *sh) if(share->unlockfunc) share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata); share->magic = 0; - free(share); + curlx_free(share); return CURLSHE_OK; } diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 369cf18967..264703d8cd 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -33,10 +33,6 @@ #include "system_win32.h" #include "curlx/warnless.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* Pointer to SSPI dispatch table */ PSecurityFunctionTable Curl_pSecFn = NULL; @@ -134,7 +130,7 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, } /* Setup the identity's user and length */ - dup_user.tchar_ptr = Curl_tcsdup(user.tchar_ptr); + dup_user.tchar_ptr = curlx_tcsdup(user.tchar_ptr); if(!dup_user.tchar_ptr) { curlx_unicodefree(useranddomain.tchar_ptr); return CURLE_OUT_OF_MEMORY; @@ -144,7 +140,7 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, dup_user.tchar_ptr = NULL; /* Setup the identity's domain and length */ - dup_domain.tchar_ptr = malloc(sizeof(TCHAR) * (domlen + 1)); + dup_domain.tchar_ptr = curlx_malloc(sizeof(TCHAR) * (domlen + 1)); if(!dup_domain.tchar_ptr) { curlx_unicodefree(useranddomain.tchar_ptr); return CURLE_OUT_OF_MEMORY; @@ -164,7 +160,7 @@ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp, passwd.tchar_ptr = curlx_convert_UTF8_to_tchar(passwdp); if(!passwd.tchar_ptr) return CURLE_OUT_OF_MEMORY; - dup_passwd.tchar_ptr = Curl_tcsdup(passwd.tchar_ptr); + dup_passwd.tchar_ptr = curlx_tcsdup(passwd.tchar_ptr); if(!dup_passwd.tchar_ptr) { curlx_unicodefree(passwd.tchar_ptr); return CURLE_OUT_OF_MEMORY; diff --git a/lib/curl_threads.c b/lib/curl_threads.c index a0308f06b2..e4536078be 100644 --- a/lib/curl_threads.c +++ b/lib/curl_threads.c @@ -31,9 +31,6 @@ #endif #include "curl_threads.h" -#include "curl_memory.h" -/* The last #include FILE should be: */ -#include "memdebug.h" #ifdef USE_THREADS_POSIX @@ -48,7 +45,7 @@ static void *curl_thread_create_thunk(void *arg) unsigned int (*func)(void *) = ac->func; void *real_arg = ac->arg; - free(ac); + curlx_free(ac); (*func)(real_arg); @@ -58,8 +55,8 @@ static void *curl_thread_create_thunk(void *arg) curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T (CURL_STDCALL *func) (void *), void *arg) { - curl_thread_t t = malloc(sizeof(pthread_t)); - struct Curl_actual_call *ac = malloc(sizeof(struct Curl_actual_call)); + curl_thread_t t = curlx_malloc(sizeof(pthread_t)); + struct Curl_actual_call *ac = curlx_malloc(sizeof(struct Curl_actual_call)); int rc; if(!(ac && t)) goto err; @@ -76,8 +73,8 @@ curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T return t; err: - free(t); - free(ac); + curlx_free(t); + curlx_free(ac); return curl_thread_t_null; } @@ -85,7 +82,7 @@ void Curl_thread_destroy(curl_thread_t *hnd) { if(*hnd != curl_thread_t_null) { pthread_detach(**hnd); - free(*hnd); + curlx_free(*hnd); *hnd = curl_thread_t_null; } } @@ -94,7 +91,7 @@ int Curl_thread_join(curl_thread_t *hnd) { int ret = (pthread_join(**hnd, NULL) == 0); - free(*hnd); + curlx_free(*hnd); *hnd = curl_thread_t_null; return ret; diff --git a/lib/curl_trc.c b/lib/curl_trc.c index 0b91315e36..cc06c77e9d 100644 --- a/lib/curl_trc.c +++ b/lib/curl_trc.c @@ -47,10 +47,6 @@ #include "vtls/vtls.h" #include "vquic/vquic.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void trc_write(struct Curl_easy *data, curl_infotype type, const char *ptr, size_t size) { diff --git a/lib/curlx/base64.c b/lib/curlx/base64.c index 3fcd709d1c..6a24c20ebd 100644 --- a/lib/curlx/base64.c +++ b/lib/curlx/base64.c @@ -30,12 +30,6 @@ #include "warnless.h" #include "base64.h" -/* The last 2 #include files should be in this order */ -#ifdef BUILDING_LIBCURL -#include "../curl_memory.h" -#endif -#include "../memdebug.h" - /* ---- Base64 Encoding/Decoding Table --- */ const char Curl_base64encdec[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -103,7 +97,7 @@ CURLcode curlx_base64_decode(const char *src, rawlen = (numQuantums * 3) - padding; /* Allocate our buffer including room for a null-terminator */ - newstr = malloc(rawlen + 1); + newstr = curlx_malloc(rawlen + 1); if(!newstr) return CURLE_OUT_OF_MEMORY; @@ -165,7 +159,7 @@ CURLcode curlx_base64_decode(const char *src, return CURLE_OK; bad: - free(newstr); + curlx_free(newstr); return CURLE_BAD_CONTENT_ENCODING; } @@ -189,7 +183,7 @@ static CURLcode base64_encode(const char *table64, if(insize > CURL_MAX_BASE64_INPUT) return CURLE_TOO_LARGE; - base64data = output = malloc((insize + 2) / 3 * 4 + 1); + base64data = output = curlx_malloc((insize + 2) / 3 * 4 + 1); if(!output) return CURLE_OUT_OF_MEMORY; diff --git a/lib/curlx/dynbuf.c b/lib/curlx/dynbuf.c index 447203e42a..e54865f933 100644 --- a/lib/curlx/dynbuf.c +++ b/lib/curlx/dynbuf.c @@ -25,10 +25,6 @@ #include "../curl_setup.h" #include "dynbuf.h" #include "../curl_printf.h" -#ifdef BUILDING_LIBCURL -#include "../curl_memory.h" -#endif -#include "../memdebug.h" #define MIN_FIRST_ALLOC 32 @@ -108,7 +104,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 include that as well when it uses this code */ - void *p = realloc(s->bufr, a); + void *p = curlx_realloc(s->bufr, a); if(!p) { curlx_dyn_free(s); return CURLE_OUT_OF_MEMORY; @@ -212,7 +208,7 @@ CURLcode curlx_dyn_vaddf(struct dynbuf *s, const char *fmt, va_list ap) if(str) { CURLcode result = dyn_nappend(s, (const unsigned char *)str, strlen(str)); - free(str); + curlx_free(str); return result; } /* If we failed, we cleanup the whole buffer and return error */ diff --git a/lib/curlx/fopen.c b/lib/curlx/fopen.c index 0dc9699206..c8dff428fc 100644 --- a/lib/curlx/fopen.c +++ b/lib/curlx/fopen.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) Daniel Stenberg, , et al. + * Copyright (C) Danieal Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -23,11 +23,8 @@ ***************************************************************************/ /* - * This file is 'mem-include-scan' clean, which means its memory allocations - * are not tracked by the curl memory tracker memdebug, so they must not use - * `CURLDEBUG` macro replacements in memdebug.h for free, malloc, etc. To avoid - * these macro replacements, wrap the names in parentheses to call the original - * versions: `ptr = (malloc)(123)`, `(free)(ptr)`, etc. + * Use system allocators to avoid infinite recursion when called by curl's + * memory tracker memdebug functions. */ #include "../curl_setup.h" @@ -103,7 +100,8 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) goto cleanup; if(!needed || needed >= max_path_len) goto cleanup; - ibuf = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + ibuf = malloc(needed * sizeof(wchar_t)); if(!ibuf) goto cleanup; if(mbstowcs_s(&count, ibuf, needed, in, needed - 1)) @@ -124,7 +122,8 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) /* skip paths that are not excessive and do not need modification */ if(needed <= MAX_PATH) goto cleanup; - fbuf = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + fbuf = malloc(needed * sizeof(wchar_t)); if(!fbuf) goto cleanup; count = (size_t)GetFullPathNameW(in_w, (DWORD)needed, fbuf, NULL); @@ -157,16 +156,19 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(needed > max_path_len) goto cleanup; - temp = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + temp = malloc(needed * sizeof(wchar_t)); if(!temp) goto cleanup; if(wcsncpy_s(temp, needed, L"\\\\?\\UNC\\", 8)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } if(wcscpy_s(temp + 8, needed, fbuf + 2)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } } @@ -176,21 +178,25 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) if(needed > max_path_len) goto cleanup; - temp = (malloc)(needed * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + temp = malloc(needed * sizeof(wchar_t)); if(!temp) goto cleanup; if(wcsncpy_s(temp, needed, L"\\\\?\\", 4)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } if(wcscpy_s(temp + 4, needed, fbuf)) { - (free)(temp); + /* !checksrc! disable BANNEDFUNC 1 */ + free(temp); goto cleanup; } } - (free)(fbuf); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fbuf); fbuf = temp; } @@ -200,7 +206,8 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) goto cleanup; if(!needed || needed >= max_path_len) goto cleanup; - obuf = (malloc)(needed); + /* !checksrc! disable BANNEDFUNC 1 */ + obuf = malloc(needed); if(!obuf) goto cleanup; if(wcstombs_s(&count, obuf, needed, fbuf, needed - 1)) @@ -215,10 +222,12 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out) #endif cleanup: - (free)(fbuf); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fbuf); #ifndef _UNICODE - (free)(ibuf); - (free)(obuf); + /* !checksrc! disable BANNEDFUNC 2 */ + free(ibuf); + free(obuf); #endif return *out ? true : false; } @@ -260,7 +269,8 @@ int curlx_win32_open(const char *filename, int oflag, ...) errno = _sopen_s(&result, target, oflag, _SH_DENYNO, pmode); #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } @@ -293,7 +303,8 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode) errno = fopen_s(&result, target, mode); #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } @@ -331,7 +342,8 @@ FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fp) errno = freopen_s(&result, target, mode, fp); #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } @@ -370,7 +382,8 @@ int curlx_win32_stat(const char *path, struct_stat *buffer) #endif #endif - (free)(fixed); + /* !checksrc! disable BANNEDFUNC 1 */ + free(fixed); return result; } diff --git a/lib/curlx/multibyte.c b/lib/curlx/multibyte.c index 9e60edf7e3..2583f30870 100644 --- a/lib/curlx/multibyte.c +++ b/lib/curlx/multibyte.c @@ -23,11 +23,8 @@ ***************************************************************************/ /* - * This file is 'mem-include-scan' clean, which means its memory allocations - * are not tracked by the curl memory tracker memdebug, so they must not use - * `CURLDEBUG` macro replacements in memdebug.h for free, malloc, etc. To avoid - * these macro replacements, wrap the names in parentheses to call the original - * versions: `ptr = (malloc)(123)`, `(free)(ptr)`, etc. + * Use system allocators to avoid infinite recursion when called by curl's + * memory tracker memdebug functions. */ #include "../curl_setup.h" @@ -48,11 +45,13 @@ wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8) int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str_utf8, -1, NULL, 0); if(str_w_len > 0) { - str_w = (malloc)(str_w_len * sizeof(wchar_t)); + /* !checksrc! disable BANNEDFUNC 1 */ + str_w = malloc(str_w_len * sizeof(wchar_t)); if(str_w) { if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w, str_w_len) == 0) { - (free)(str_w); + /* !checksrc! disable BANNEDFUNC 1 */ + free(str_w); return NULL; } } @@ -70,11 +69,13 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w) int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL, 0, NULL, NULL); if(bytes > 0) { - str_utf8 = (malloc)(bytes); + /* !checksrc! disable BANNEDFUNC 1 */ + str_utf8 = malloc(bytes); if(str_utf8) { if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes, NULL, NULL) == 0) { - (free)(str_utf8); + /* !checksrc! disable BANNEDFUNC 1 */ + free(str_utf8); return NULL; } } diff --git a/lib/curlx/multibyte.h b/lib/curlx/multibyte.h index 8b698c1b73..c992214a95 100644 --- a/lib/curlx/multibyte.h +++ b/lib/curlx/multibyte.h @@ -44,11 +44,8 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); * * Allocated memory should be free'd with curlx_unicodefree(). * - * Note: Because these are curlx functions their memory usage is not tracked - * by the curl memory tracker memdebug. you will notice that curlx - * function-like macros call free and strdup in parentheses, eg (strdup)(ptr), - * and that is to ensure that the curl memdebug override macros do not replace - * them. + * Use system allocators to avoid infinite recursion when called by curl's + * memory tracker memdebug functions. */ #if defined(UNICODE) && defined(_WIN32) @@ -65,8 +62,13 @@ typedef union { #else -#define curlx_convert_UTF8_to_tchar(ptr) (strdup)(ptr) -#define curlx_convert_tchar_to_UTF8(ptr) (strdup)(ptr) +#ifdef _WIN32 +#define curlx_convert_UTF8_to_tchar(ptr) _strdup(ptr) +#define curlx_convert_tchar_to_UTF8(ptr) _strdup(ptr) +#else +#define curlx_convert_UTF8_to_tchar(ptr) strdup(ptr) +#define curlx_convert_tchar_to_UTF8(ptr) strdup(ptr) +#endif typedef union { char *tchar_ptr; @@ -78,6 +80,6 @@ typedef union { #endif /* UNICODE && _WIN32 */ /* the purpose of this macro is to free() without being traced by memdebug */ -#define curlx_unicodefree(ptr) (free)(ptr) +#define curlx_unicodefree(ptr) free(ptr) #endif /* HEADER_CURL_MULTIBYTE_H */ diff --git a/lib/curlx/strerr.c b/lib/curlx/strerr.c index c33d107011..3dbeab82ee 100644 --- a/lib/curlx/strerr.c +++ b/lib/curlx/strerr.c @@ -37,9 +37,6 @@ #include "winapi.h" #include "snprintf.h" #include "strerr.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" #ifdef USE_WINSOCK /* This is a helper function for curlx_strerror that converts Winsock error diff --git a/lib/curlx/version_win32.c b/lib/curlx/version_win32.c index cc86b71d3e..9ab72c2fd5 100644 --- a/lib/curlx/version_win32.c +++ b/lib/curlx/version_win32.c @@ -30,10 +30,6 @@ #include "version_win32.h" #include "warnless.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* This Unicode version struct works for VerifyVersionInfoW (OSVERSIONINFOEXW) and RtlVerifyVersionInfo (RTLOSVERSIONINFOEXW) */ struct OUR_OSVERSIONINFOEXW { diff --git a/lib/cw-out.c b/lib/cw-out.c index 36cfc36aca..4561546d19 100644 --- a/lib/cw-out.c +++ b/lib/cw-out.c @@ -35,10 +35,6 @@ #include "cw-out.h" #include "cw-pause.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /** * OVERALL DESIGN of this client writer @@ -85,7 +81,7 @@ struct cw_out_buf { static struct cw_out_buf *cw_out_buf_create(cw_out_type otype) { - struct cw_out_buf *cwbuf = calloc(1, sizeof(*cwbuf)); + struct cw_out_buf *cwbuf = curlx_calloc(1, sizeof(*cwbuf)); if(cwbuf) { cwbuf->type = otype; curlx_dyn_init(&cwbuf->b, DYN_PAUSE_BUFFER); @@ -97,7 +93,7 @@ static void cw_out_buf_free(struct cw_out_buf *cwbuf) { if(cwbuf) { curlx_dyn_free(&cwbuf->b); - free(cwbuf); + curlx_free(cwbuf); } } diff --git a/lib/cw-pause.c b/lib/cw-pause.c index 1af4e8fa41..2a98667ae4 100644 --- a/lib/cw-pause.c +++ b/lib/cw-pause.c @@ -34,10 +34,6 @@ #include "sendf.h" #include "cw-pause.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* body dynbuf sizes */ #define CW_PAUSE_BUF_CHUNK (16 * 1024) @@ -52,7 +48,7 @@ struct cw_pause_buf { static struct cw_pause_buf *cw_pause_buf_create(int type, size_t buflen) { - struct cw_pause_buf *cwbuf = calloc(1, sizeof(*cwbuf)); + struct cw_pause_buf *cwbuf = curlx_calloc(1, sizeof(*cwbuf)); if(cwbuf) { cwbuf->type = type; if(type & CLIENTWRITE_BODY) @@ -68,7 +64,7 @@ static void cw_pause_buf_free(struct cw_pause_buf *cwbuf) { if(cwbuf) { Curl_bufq_free(&cwbuf->b); - free(cwbuf); + curlx_free(cwbuf); } } diff --git a/lib/dict.c b/lib/dict.c index 5c7ba7f622..f208892f73 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -60,11 +60,6 @@ #include "progress.h" #include "dict.h" -/* The last 2 #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - - #define DICT_MATCH "/MATCH:" #define DICT_MATCH2 "/M:" #define DICT_MATCH3 "/FIND:" @@ -172,7 +167,7 @@ static CURLcode sendf(struct Curl_easy *data, const char *fmt, ...) break; } - free(s); /* free the output string */ + curlx_free(s); /* free the output string */ return result; } @@ -310,8 +305,8 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) } error: - free(eword); - free(path); + curlx_free(eword); + curlx_free(path); return result; } #endif /* CURL_DISABLE_DICT */ diff --git a/lib/dllmain.c b/lib/dllmain.c index 011090589b..7b7d3c7e2e 100644 --- a/lib/dllmain.c +++ b/lib/dllmain.c @@ -28,10 +28,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* DllMain() must only be defined for Windows DLL builds. */ #if defined(_WIN32) && !defined(CURL_STATICLIB) diff --git a/lib/doh.c b/lib/doh.c index 0712981a97..d7b1d54c25 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -41,10 +41,6 @@ #include "escape.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define DNS_CLASS_IN 0x01 #ifndef CURL_DISABLE_VERBOSE_STRINGS @@ -269,7 +265,7 @@ static void doh_probe_dtor(void *key, size_t klen, void *e) struct doh_request *doh_req = e; curl_slist_free_all(doh_req->req_hds); curlx_dyn_free(&doh_req->resp_body); - free(e); + curlx_free(e); } } @@ -296,7 +292,7 @@ static CURLcode doh_probe_run(struct Curl_easy *data, *pmid = UINT32_MAX; - doh_req = calloc(1, sizeof(*doh_req)); + doh_req = curlx_calloc(1, sizeof(*doh_req)); if(!doh_req) return CURLE_OUT_OF_MEMORY; doh_req->dnstype = dnstype; @@ -462,12 +458,12 @@ CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, data->state.async.done = FALSE; data->state.async.port = port; data->state.async.ip_version = ip_version; - data->state.async.hostname = strdup(hostname); + data->state.async.hostname = curlx_strdup(hostname); if(!data->state.async.hostname) return CURLE_OUT_OF_MEMORY; /* start clean, consider allocating this struct on demand */ - data->state.async.doh = dohp = calloc(1, sizeof(struct doh_probes)); + data->state.async.doh = dohp = curlx_calloc(1, sizeof(struct doh_probes)); if(!dohp) return CURLE_OUT_OF_MEMORY; @@ -518,7 +514,7 @@ CURLcode Curl_doh(struct Curl_easy *data, const char *hostname, qname ? qname : hostname, data->set.str[STRING_DOH], data->multi, &dohp->probe_resp[DOH_SLOT_HTTPS_RR].probe_mid); - free(qname); + curlx_free(qname); if(result) goto error; dohp->pending++; @@ -963,7 +959,7 @@ static CURLcode doh2ai(const struct dohentry *de, const char *hostname, addrtype = AF_INET; } - ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen); + ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen); if(!ai) { result = CURLE_OUT_OF_MEMORY; break; @@ -1130,7 +1126,7 @@ UNITTEST CURLcode doh_resp_decode_httpsrr(struct Curl_easy *data, *hrr = NULL; if(len <= 2) return CURLE_BAD_FUNCTION_ARGUMENT; - lhrr = calloc(1, sizeof(struct Curl_https_rrinfo)); + lhrr = curlx_calloc(1, sizeof(struct Curl_https_rrinfo)); if(!lhrr) return CURLE_OUT_OF_MEMORY; lhrr->priority = doh_get16bit(cp, 0); diff --git a/lib/dynhds.c b/lib/dynhds.c index 95d415bf0b..ebe1beae58 100644 --- a/lib/dynhds.c +++ b/lib/dynhds.c @@ -31,10 +31,6 @@ #include #endif /* USE_NGHTTP2 */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static struct dynhds_entry * entry_new(const char *name, size_t namelen, @@ -45,7 +41,7 @@ entry_new(const char *name, size_t namelen, DEBUGASSERT(name); DEBUGASSERT(value); - e = calloc(1, sizeof(*e) + namelen + valuelen + 2); + e = curlx_calloc(1, sizeof(*e) + namelen + valuelen + 2); if(!e) return NULL; e->name = p = ((char *)e) + sizeof(*e); @@ -68,7 +64,7 @@ entry_append(struct dynhds_entry *e, char *p; DEBUGASSERT(value); - e2 = calloc(1, sizeof(*e) + e->namelen + valuelen2 + 2); + e2 = curlx_calloc(1, sizeof(*e) + e->namelen + valuelen2 + 2); if(!e2) return NULL; e2->name = p = ((char *)e2) + sizeof(*e2); @@ -85,7 +81,7 @@ entry_append(struct dynhds_entry *e, static void entry_free(struct dynhds_entry *e) { - free(e); + curlx_free(e); } void Curl_dynhds_init(struct dynhds *dynhds, size_t max_entries, @@ -186,7 +182,7 @@ entry = entry_new(name, namelen, value, valuelen, dynhds->opts); if(dynhds->max_entries && nallc > dynhds->max_entries) nallc = dynhds->max_entries; - nhds = calloc(nallc, sizeof(struct dynhds_entry *)); + nhds = curlx_calloc(nallc, sizeof(struct dynhds_entry *)); if(!nhds) goto out; if(dynhds->hds) { @@ -374,7 +370,7 @@ CURLcode Curl_dynhds_h1_dprint(struct dynhds *dynhds, struct dynbuf *dbuf) nghttp2_nv *Curl_dynhds_to_nva(struct dynhds *dynhds, size_t *pcount) { - nghttp2_nv *nva = calloc(1, sizeof(nghttp2_nv) * dynhds->hds_len); + nghttp2_nv *nva = curlx_calloc(1, sizeof(nghttp2_nv) * dynhds->hds_len); size_t i; *pcount = 0; diff --git a/lib/easy.c b/lib/easy.c index db6c419c57..476f63c74d 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -80,10 +80,6 @@ #include "easy_lock.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* true globals -- for curl_global_init() and curl_global_cleanup() */ static unsigned int initialized; static long easy_init_flags; @@ -198,7 +194,7 @@ static CURLcode global_init(long flags, bool memoryfuncs) #ifdef DEBUGBUILD if(getenv("CURL_GLOBAL_INIT")) /* alloc data that will leak if *cleanup() is not called! */ - leakpointer = malloc(1); + leakpointer = curlx_malloc(1); #endif return CURLE_OK; @@ -297,7 +293,7 @@ void curl_global_cleanup(void) Curl_ssh_cleanup(); #ifdef DEBUGBUILD - free(leakpointer); + curlx_free(leakpointer); #endif easy_init_flags = 0; @@ -478,7 +474,7 @@ static int events_socket(CURL *easy, /* easy handle */ prev->next = nxt; else ev->list = nxt; - free(m); + curlx_free(m); infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s); } else { @@ -504,7 +500,7 @@ static int events_socket(CURL *easy, /* easy handle */ DEBUGASSERT(0); } else { - m = malloc(sizeof(struct socketmonitor)); + m = curlx_malloc(sizeof(struct socketmonitor)); if(m) { m->next = ev->list; m->socket.fd = s; @@ -927,7 +923,7 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src) i = STRING_COPYPOSTFIELDS; if(src->set.str[i]) { if(src->set.postfieldsize == -1) - dst->set.str[i] = strdup(src->set.str[i]); + 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], @@ -968,7 +964,7 @@ CURL *curl_easy_duphandle(CURL *d) if(!GOOD_EASY_HANDLE(data)) goto fail; - outcurl = calloc(1, sizeof(struct Curl_easy)); + outcurl = curlx_calloc(1, sizeof(struct Curl_easy)); if(!outcurl) goto fail; @@ -1022,14 +1018,14 @@ CURL *curl_easy_duphandle(CURL *d) #endif if(data->state.url) { - outcurl->state.url = strdup(data->state.url); + outcurl->state.url = curlx_strdup(data->state.url); if(!outcurl->state.url) goto fail; outcurl->state.url_alloc = TRUE; } if(data->state.referer) { - outcurl->state.referer = strdup(data->state.referer); + outcurl->state.referer = curlx_strdup(data->state.referer); if(!outcurl->state.referer) goto fail; outcurl->state.referer_alloc = TRUE; @@ -1073,13 +1069,13 @@ fail: if(outcurl) { #ifndef CURL_DISABLE_COOKIES - free(outcurl->cookies); + curlx_free(outcurl->cookies); #endif curlx_dyn_free(&outcurl->state.headerb); Curl_altsvc_cleanup(&outcurl->asi); Curl_hsts_cleanup(&outcurl->hsts); Curl_freeset(outcurl); - free(outcurl); + curlx_free(outcurl); } return NULL; diff --git a/lib/escape.c b/lib/escape.c index fdc6e438ab..04b46f7a9e 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -37,10 +37,6 @@ struct Curl_easy; #include "curlx/strparse.h" #include "curl_printf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* for ABI-compatibility with previous versions */ char *curl_escape(const char *string, int inlength) { @@ -68,7 +64,7 @@ char *curl_easy_escape(CURL *data, const char *string, length = (inlength ? (size_t)inlength : strlen(string)); if(!length) - return strdup(""); + return curlx_strdup(""); curlx_dyn_init(&d, length * 3 + 1); @@ -120,7 +116,7 @@ CURLcode Curl_urldecode(const char *string, size_t length, DEBUGASSERT(ctrl >= REJECT_NADA); /* crash on TRUE/FALSE */ alloc = (length ? length : strlen(string)); - ns = malloc(alloc + 1); + ns = curlx_malloc(alloc + 1); if(!ns) return CURLE_OUT_OF_MEMORY; @@ -196,7 +192,7 @@ char *curl_easy_unescape(CURL *data, const char *string, the library's memory system */ void curl_free(void *p) { - free(p); + curlx_free(p); } /* diff --git a/lib/fake_addrinfo.c b/lib/fake_addrinfo.c index 9789d1ef62..7d5da09ead 100644 --- a/lib/fake_addrinfo.c +++ b/lib/fake_addrinfo.c @@ -31,10 +31,6 @@ #include #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void r_freeaddrinfo(struct addrinfo *cahead) { struct addrinfo *canext; @@ -42,7 +38,7 @@ void r_freeaddrinfo(struct addrinfo *cahead) for(ca = cahead; ca; ca = canext) { canext = ca->ai_next; - free(ca); + curlx_free(ca); } } @@ -90,7 +86,7 @@ static struct addrinfo *mk_getaddrinfo(const struct ares_addrinfo *aihead) if((size_t)ai->ai_addrlen < ss_size) continue; - ca = malloc(sizeof(struct addrinfo) + ss_size + namelen); + ca = curlx_malloc(sizeof(struct addrinfo) + ss_size + namelen); if(!ca) { r_freeaddrinfo(cafirst); return NULL; diff --git a/lib/file.c b/lib/file.c index 3de92408c4..2f30a0297c 100644 --- a/lib/file.c +++ b/lib/file.c @@ -68,10 +68,6 @@ #include "curlx/warnless.h" #include "curl_range.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(_WIN32) || defined(MSDOS) #define DOS_FILESYSTEM 1 #elif defined(__amigaos4__) @@ -148,7 +144,7 @@ static void file_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; file_cleanup(file); - free(file); + curlx_free(file); } static CURLcode file_setup_connection(struct Curl_easy *data, @@ -157,7 +153,7 @@ static CURLcode file_setup_connection(struct Curl_easy *data, struct FILEPROTO *filep; (void)conn; /* allocate the FILE specific struct */ - filep = calloc(1, sizeof(*filep)); + filep = curlx_calloc(1, sizeof(*filep)); if(!filep || Curl_meta_set(data, CURL_META_FILE_EASY, filep, file_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -269,7 +265,7 @@ static CURLcode file_connect(struct Curl_easy *data, bool *done) file->path = real_path; #endif #endif - free(file->freepath); + curlx_free(file->freepath); file->freepath = real_path; /* free this when done */ file->fd = fd; diff --git a/lib/fileinfo.c b/lib/fileinfo.c index bddd3fe6fb..83d2ef0d00 100644 --- a/lib/fileinfo.c +++ b/lib/fileinfo.c @@ -27,13 +27,10 @@ #ifndef CURL_DISABLE_FTP #include "fileinfo.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" struct fileinfo *Curl_fileinfo_alloc(void) { - return calloc(1, sizeof(struct fileinfo)); + return curlx_calloc(1, sizeof(struct fileinfo)); } void Curl_fileinfo_cleanup(struct fileinfo *finfo) @@ -42,7 +39,7 @@ void Curl_fileinfo_cleanup(struct fileinfo *finfo) return; curlx_dyn_free(&finfo->buf); - free(finfo); + curlx_free(finfo); } #endif diff --git a/lib/formdata.c b/lib/formdata.c index 416bcad4f5..d4bfed89be 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -40,10 +40,6 @@ struct Curl_easy; #include "curlx/fopen.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define HTTPPOST_PTRNAME CURL_HTTPPOST_PTRNAME #define HTTPPOST_FILENAME CURL_HTTPPOST_FILENAME @@ -76,7 +72,7 @@ AddHttpPost(struct FormInfo *src, if((src->bufferlength > LONG_MAX) || (namelength > LONG_MAX)) /* avoid overflow in typecasts below */ return NULL; - post = calloc(1, sizeof(struct curl_httppost)); + post = curlx_calloc(1, sizeof(struct curl_httppost)); if(post) { post->name = src->name; post->namelength = (long)namelength; @@ -127,7 +123,7 @@ static struct FormInfo *AddFormInfo(char *value, struct FormInfo *parent_form_info) { struct FormInfo *form_info; - form_info = calloc(1, sizeof(struct FormInfo)); + form_info = curlx_calloc(1, sizeof(struct FormInfo)); if(!form_info) return NULL; if(value) @@ -262,7 +258,7 @@ static CURLFORMcode FormAddCheck(struct FormInfo *first_form, type = FILE_CONTENTTYPE_DEFAULT; /* our contenttype is missing */ - form->contenttype = strdup(type); + form->contenttype = curlx_strdup(type); if(!form->contenttype) return CURL_FORMADD_MEMORY; @@ -320,7 +316,7 @@ static void free_chain(struct curl_httppost *c) struct curl_httppost *next = c->next; if(c->more) free_chain(c->more); - free(c); + curlx_free(c); c = next; } } @@ -346,7 +342,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, /* * We need to allocate the first struct to fill in. */ - first_form = calloc(1, sizeof(struct FormInfo)); + first_form = curlx_calloc(1, sizeof(struct FormInfo)); if(!first_form) return CURL_FORMADD_MEMORY; @@ -458,7 +454,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(!array_state) avalue = va_arg(params, char *); if(avalue) { - curr->value = strdup(avalue); + curr->value = curlx_strdup(avalue); if(!curr->value) retval = CURL_FORMADD_MEMORY; else { @@ -479,13 +475,13 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->value) { if(curr->flags & HTTPPOST_FILENAME) { if(avalue) { - char *fname = strdup(avalue); + char *fname = curlx_strdup(avalue); if(!fname) retval = CURL_FORMADD_MEMORY; else { form = AddFormInfo(fname, NULL, curr); if(!form) { - free(fname); + curlx_free(fname); retval = CURL_FORMADD_MEMORY; } else { @@ -503,7 +499,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, } else { if(avalue) { - curr->value = strdup(avalue); + curr->value = curlx_strdup(avalue); if(!curr->value) retval = CURL_FORMADD_MEMORY; else { @@ -566,13 +562,13 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->contenttype) { if(curr->flags & HTTPPOST_FILENAME) { if(avalue) { - char *type = strdup(avalue); + char *type = curlx_strdup(avalue); if(!type) retval = CURL_FORMADD_MEMORY; else { form = AddFormInfo(NULL, type, curr); if(!form) { - free(type); + curlx_free(type); retval = CURL_FORMADD_MEMORY; } else { @@ -590,7 +586,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, } else { if(avalue) { - curr->contenttype = strdup(avalue); + curr->contenttype = curlx_strdup(avalue); if(!curr->contenttype) retval = CURL_FORMADD_MEMORY; else @@ -623,7 +619,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, if(curr->showfilename) retval = CURL_FORMADD_OPTION_TWICE; else { - curr->showfilename = strdup(avalue); + curr->showfilename = curlx_strdup(avalue); if(!curr->showfilename) retval = CURL_FORMADD_MEMORY; else @@ -650,7 +646,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, now by the httppost linked list */ while(first_form) { struct FormInfo *ptr = first_form->more; - free(first_form); + curlx_free(first_form); first_form = ptr; } @@ -743,14 +739,14 @@ void curl_formfree(struct curl_httppost *form) curl_formfree(form->more); if(!(form->flags & HTTPPOST_PTRNAME)) - free(form->name); /* free the name */ + curlx_free(form->name); /* free the name */ if(!(form->flags & (HTTPPOST_PTRCONTENTS|HTTPPOST_BUFFER|HTTPPOST_CALLBACK)) ) - free(form->contents); /* free the contents */ - free(form->contenttype); /* free the content type */ - free(form->showfilename); /* free the faked filename */ - free(form); /* free the struct */ + curlx_free(form->contents); /* free the contents */ + curlx_free(form->contenttype); /* free the content type */ + curlx_free(form->showfilename); /* free the faked filename */ + curlx_free(form); /* free the struct */ form = next; } while(form); /* continue */ } @@ -768,7 +764,7 @@ static CURLcode setname(curl_mimepart *part, const char *name, size_t len) if(!zname) return CURLE_OUT_OF_MEMORY; res = curl_mime_name(part, zname); - free(zname); + curlx_free(zname); return res; } diff --git a/lib/ftp.c b/lib/ftp.c index ce40012268..b2b15a89dc 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -72,10 +72,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifndef NI_MAXHOST #define NI_MAXHOST 1025 #endif @@ -1419,7 +1415,7 @@ static CURLcode ftp_state_list(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; result = Curl_pp_sendf(data, &ftpc->pp, "%s", cmd); - free(cmd); + curlx_free(cmd); if(!result) ftp_state(data, ftpc, FTP_LIST); @@ -1770,12 +1766,12 @@ static CURLcode ftp_control_addr_dup(struct Curl_easy *data, not the ftp host. */ #ifndef CURL_DISABLE_PROXY if(conn->bits.tunnel_proxy || conn->bits.socksproxy) - *newhostp = strdup(conn->host.name); + *newhostp = curlx_strdup(conn->host.name); else #endif if(!Curl_conn_get_ip_info(data, conn, FIRSTSOCKET, &is_ipv6, &ipquad) && *ipquad.remote_ip) - *newhostp = strdup(ipquad.remote_ip); + *newhostp = curlx_strdup(ipquad.remote_ip); else { /* failed to get the remote_ip of the DATA connection */ failf(data, "unable to get peername of DATA connection"); @@ -1934,7 +1930,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, /* postponed address resolution in case of tcp fastopen */ if(conn->bits.tcp_fastopen && !conn->bits.reuse && !newhost[0]) { - free(newhost); + curlx_free(newhost); result = ftp_control_addr_dup(data, &newhost); if(result) goto error; @@ -1956,7 +1952,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, if(result) { if(ftpc->count1 == 0 && ftpcode == 229) { - free(newhost); + curlx_free(newhost); return ftp_epsv_disable(data, ftpc, conn); } @@ -1973,9 +1969,9 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, /* this just dumps information about this second connection */ ftp_pasv_verbose(data, dns->addr, newhost, connectport); - free(conn->secondaryhostname); + curlx_free(conn->secondaryhostname); conn->secondary_port = newport; - conn->secondaryhostname = strdup(newhost); + conn->secondaryhostname = curlx_strdup(newhost); if(!conn->secondaryhostname) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -1985,7 +1981,7 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, ftp_state(data, ftpc, FTP_STOP); /* this phase is completed */ error: - free(newhost); + curlx_free(newhost); return result; } @@ -2723,17 +2719,17 @@ static CURLcode ftp_pwd_resp(struct Curl_easy *data, if(!ftpc->server_os && dir[0] != '/') { result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SYST"); if(result) { - free(dir); + curlx_free(dir); return result; } } - free(ftpc->entrypath); + curlx_free(ftpc->entrypath); ftpc->entrypath = dir; /* remember this */ infof(data, "Entry path is '%s'", ftpc->entrypath); /* also save it where getinfo can access it: */ - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(ftpc->entrypath); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(ftpc->entrypath); if(!data->state.most_recent_ftp_entrypath) return CURLE_OUT_OF_MEMORY; @@ -2961,18 +2957,18 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, /* Force OS400 name format 1. */ result = Curl_pp_sendf(data, &ftpc->pp, "%s", "SITE NAMEFMT 1"); if(result) { - free(os); + curlx_free(os); return result; } /* remember target server OS */ - free(ftpc->server_os); + curlx_free(ftpc->server_os); ftpc->server_os = os; ftp_state(data, ftpc, FTP_NAMEFMT); break; } /* Nothing special for the target server. */ /* remember target server OS */ - free(ftpc->server_os); + curlx_free(ftpc->server_os); ftpc->server_os = os; } else { @@ -3277,7 +3273,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, * the error path) */ ftpc->ctl_valid = FALSE; /* mark control connection as bad */ connclose(conn, "FTP: out of memory!"); /* mark for connection closure */ - free(ftpc->prevpath); + curlx_free(ftpc->prevpath); ftpc->prevpath = NULL; /* no path remembering */ } else { /* remember working directory for connection reuse */ @@ -3288,7 +3284,7 @@ static CURLcode ftp_done(struct Curl_easy *data, CURLcode status, else { size_t pathLen = strlen(ftpc->rawpath); - free(ftpc->prevpath); + curlx_free(ftpc->prevpath); if(!ftpc->cwdfail) { if(data->set.ftp_filemethod == FTPFILE_NOCWD) @@ -3757,7 +3753,7 @@ static void wc_data_dtor(void *ptr) struct ftp_wc *ftpwc = ptr; if(ftpwc && ftpwc->parser) Curl_ftp_parselist_data_free(&ftpwc->parser); - free(ftpwc); + curlx_free(ftpwc); } static CURLcode init_wc_data(struct Curl_easy *data, @@ -3777,14 +3773,14 @@ static CURLcode init_wc_data(struct Curl_easy *data, wildcard->state = CURLWC_CLEAN; return ftp_parse_url_path(data, ftpc, ftp); } - wildcard->pattern = strdup(last_slash); + wildcard->pattern = curlx_strdup(last_slash); if(!wildcard->pattern) return CURLE_OUT_OF_MEMORY; last_slash[0] = '\0'; /* cut file from path */ } else { /* there is only 'wildcard pattern' or nothing */ if(path[0]) { - wildcard->pattern = strdup(path); + wildcard->pattern = curlx_strdup(path); if(!wildcard->pattern) return CURLE_OUT_OF_MEMORY; path[0] = '\0'; @@ -3799,7 +3795,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, resources for wildcard transfer */ /* allocate ftp protocol specific wildcard data */ - ftpwc = calloc(1, sizeof(struct ftp_wc)); + ftpwc = curlx_calloc(1, sizeof(struct ftp_wc)); if(!ftpwc) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -3825,7 +3821,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, goto fail; } - wildcard->path = strdup(ftp->path); + wildcard->path = curlx_strdup(ftp->path); if(!wildcard->path) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -3846,7 +3842,7 @@ static CURLcode init_wc_data(struct Curl_easy *data, fail: if(ftpwc) { Curl_ftp_parselist_data_free(&ftpwc->parser); - free(ftpwc); + curlx_free(ftpwc); } Curl_safefree(wildcard->pattern); wildcard->dtor = ZERO_NULL; @@ -3904,7 +3900,7 @@ static CURLcode wc_statemach(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; /* switch default ftp->path and tmp_path */ - free(ftp->pathalloc); + curlx_free(ftp->pathalloc); ftp->pathalloc = ftp->path = tmp_path; infof(data, "Wildcard - START of \"%s\"", finfo->filename); @@ -4179,7 +4175,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data, if(dirlen == 0) dirlen = 1; - ftpc->dirs = calloc(1, sizeof(ftpc->dirs[0])); + ftpc->dirs = curlx_calloc(1, sizeof(ftpc->dirs[0])); if(!ftpc->dirs) return CURLE_OUT_OF_MEMORY; @@ -4205,7 +4201,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data, return CURLE_URL_MALFORMAT; if(dirAlloc) { - ftpc->dirs = calloc(dirAlloc, sizeof(ftpc->dirs[0])); + ftpc->dirs = curlx_calloc(dirAlloc, sizeof(ftpc->dirs[0])); if(!ftpc->dirs) return CURLE_OUT_OF_MEMORY; @@ -4372,7 +4368,7 @@ static void ftp_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; Curl_safefree(ftp->pathalloc); - free(ftp); + curlx_free(ftp); } static void ftp_conn_dtor(void *key, size_t klen, void *entry) @@ -4387,7 +4383,7 @@ static void ftp_conn_dtor(void *key, size_t klen, void *entry) Curl_safefree(ftpc->prevpath); Curl_safefree(ftpc->server_os); Curl_pp_disconnect(&ftpc->pp); - free(ftpc); + curlx_free(ftpc); } static void type_url_check(struct Curl_easy *data, struct FTP *ftp) @@ -4426,19 +4422,19 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, CURLcode result = CURLE_OK; struct ftp_conn *ftpc; - ftp = calloc(1, sizeof(*ftp)); + ftp = curlx_calloc(1, sizeof(*ftp)); if(!ftp || Curl_meta_set(data, CURL_META_FTP_EASY, ftp, ftp_easy_dtor)) return CURLE_OUT_OF_MEMORY; - ftpc = calloc(1, sizeof(*ftpc)); + ftpc = curlx_calloc(1, sizeof(*ftpc)); if(!ftpc || Curl_conn_meta_set(conn, CURL_META_FTP_CONN, ftpc, ftp_conn_dtor)) return CURLE_OUT_OF_MEMORY; /* clone connection related data that is FTP specific */ if(data->set.str[STRING_FTP_ACCOUNT]) { - ftpc->account = strdup(data->set.str[STRING_FTP_ACCOUNT]); + ftpc->account = curlx_strdup(data->set.str[STRING_FTP_ACCOUNT]); if(!ftpc->account) { Curl_conn_meta_remove(conn, CURL_META_FTP_CONN); return CURLE_OUT_OF_MEMORY; @@ -4446,7 +4442,7 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data, } if(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]) { ftpc->alternative_to_user = - strdup(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); + curlx_strdup(data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]); if(!ftpc->alternative_to_user) { Curl_safefree(ftpc->account); Curl_conn_meta_remove(conn, CURL_META_FTP_CONN); diff --git a/lib/ftplistparser.c b/lib/ftplistparser.c index d8d155d5c2..b62fa47f65 100644 --- a/lib/ftplistparser.c +++ b/lib/ftplistparser.c @@ -52,10 +52,6 @@ #include "multiif.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - typedef enum { PL_UNIX_TOTALSIZE = 0, PL_UNIX_FILETYPE, @@ -205,18 +201,18 @@ void Curl_wildcard_dtor(struct WildcardData **wcp) DEBUGASSERT(wc->ftpwc == NULL); Curl_llist_destroy(&wc->filelist, NULL); - free(wc->path); + curlx_free(wc->path); wc->path = NULL; - free(wc->pattern); + curlx_free(wc->pattern); wc->pattern = NULL; wc->state = CURLWC_INIT; - free(wc); + curlx_free(wc); *wcp = NULL; } struct ftp_parselist_data *Curl_ftp_parselist_data_alloc(void) { - return calloc(1, sizeof(struct ftp_parselist_data)); + return curlx_calloc(1, sizeof(struct ftp_parselist_data)); } @@ -225,7 +221,7 @@ void Curl_ftp_parselist_data_free(struct ftp_parselist_data **parserp) struct ftp_parselist_data *parser = *parserp; if(parser) Curl_fileinfo_cleanup(parser->file_data); - free(parser); + curlx_free(parser); *parserp = NULL; } diff --git a/lib/getenv.c b/lib/getenv.c index a2d8056fcc..73c62d99cd 100644 --- a/lib/getenv.c +++ b/lib/getenv.c @@ -25,9 +25,6 @@ #include "curl_setup.h" #include -#include "curl_memory.h" - -#include "memdebug.h" static char *GetEnv(const char *variable) { @@ -45,9 +42,9 @@ static char *GetEnv(const char *variable) const DWORD max = 32768; /* max env var size from MSCRT source */ for(;;) { - tmp = realloc(buf, rc); + tmp = curlx_realloc(buf, rc); if(!tmp) { - free(buf); + curlx_free(buf); return NULL; } @@ -58,7 +55,7 @@ static char *GetEnv(const char *variable) Since getenv does not make that distinction we ignore it as well. */ rc = GetEnvironmentVariableA(variable, buf, bufsize); if(!rc || rc == bufsize || rc > max) { - free(buf); + curlx_free(buf); return NULL; } @@ -70,7 +67,7 @@ static char *GetEnv(const char *variable) } #else char *env = getenv(variable); - return (env && env[0]) ? strdup(env) : NULL; + return (env && env[0]) ? curlx_strdup(env) : NULL; #endif } diff --git a/lib/getinfo.c b/lib/getinfo.c index 01c7279356..14244d087b 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -34,10 +34,6 @@ #include "progress.h" #include "curlx/strparse.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Initialize statistical and informational data. * @@ -74,10 +70,10 @@ void Curl_initinfo(struct Curl_easy *data) info->httpauthpicked = 0; info->numconnects = 0; - free(info->contenttype); + curlx_free(info->contenttype); info->contenttype = NULL; - free(info->wouldredirect); + curlx_free(info->wouldredirect); info->wouldredirect = NULL; memset(&info->primary, 0, sizeof(info->primary)); @@ -137,7 +133,7 @@ static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info, case CURLINFO_FTP_ENTRY_PATH: /* Return the entrypath string from the most recent connection. This pointer was copied from the connectdata structure by FTP. - The actual string may be free()ed by subsequent libcurl calls so + The actual string may be freed by subsequent libcurl calls so it must be copied to a safer area before the next libcurl call. Callers must never free it themselves. */ *param_charp = data->state.most_recent_ftp_entrypath; diff --git a/lib/gopher.c b/lib/gopher.c index 45d43f6ebd..93e9287c99 100644 --- a/lib/gopher.c +++ b/lib/gopher.c @@ -40,10 +40,6 @@ #include "escape.h" #include "curlx/warnless.h" -/* The last 2 #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Forward declarations. */ @@ -153,7 +149,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) if(query) gopherpath = curl_maprintf("%s?%s", path, query); else - gopherpath = strdup(path); + gopherpath = curlx_strdup(path); if(!gopherpath) return CURLE_OUT_OF_MEMORY; @@ -162,7 +158,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) if(strlen(gopherpath) <= 2) { buf = ""; buf_len = 0; - free(gopherpath); + curlx_free(gopherpath); } else { char *newp; @@ -173,7 +169,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) /* ... and finally unescape */ result = Curl_urldecode(newp, 0, &buf_alloc, &buf_len, REJECT_ZERO); - free(gopherpath); + curlx_free(gopherpath); if(result) return result; buf = buf_alloc; @@ -224,7 +220,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) } } - free(buf_alloc); + curlx_free(buf_alloc); if(!result) result = Curl_xfer_send(data, "\r\n", 2, FALSE, &nwritten); diff --git a/lib/hash.c b/lib/hash.c index 8312fbf050..2d91c855e6 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -28,10 +28,6 @@ #include "hash.h" #include "llist.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" /* random patterns for API verification */ #ifdef DEBUGBUILD @@ -115,7 +111,7 @@ hash_elem_create(const void *key, size_t key_len, const void *p, struct Curl_hash_element *he; /* allocate the struct plus memory after it to store the key */ - he = malloc(sizeof(struct Curl_hash_element) + key_len); + he = curlx_malloc(sizeof(struct Curl_hash_element) + key_len); if(he) { he->next = NULL; /* copy the key */ @@ -145,7 +141,7 @@ static void hash_elem_destroy(struct Curl_hash *h, struct Curl_hash_element *he) { hash_elem_clear_ptr(h, he); - free(he); + curlx_free(he); } static void hash_elem_unlink(struct Curl_hash *h, @@ -177,7 +173,7 @@ void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p, DEBUGASSERT(h->slots); DEBUGASSERT(h->init == HASHINIT); if(!h->table) { - h->table = calloc(h->slots, sizeof(struct Curl_hash_element *)); + h->table = curlx_calloc(h->slots, sizeof(struct Curl_hash_element *)); if(!h->table) return NULL; /* OOM */ } diff --git a/lib/headers.c b/lib/headers.c index feb52e087d..91715fd51d 100644 --- a/lib/headers.c +++ b/lib/headers.c @@ -30,10 +30,6 @@ #include "headers.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_HEADERS_API) /* Generate the curl_header struct for the user. This function MUST assign all @@ -317,7 +313,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, return CURLE_TOO_LARGE; } - hs = calloc(1, sizeof(*hs) + hlen); + hs = curlx_calloc(1, sizeof(*hs) + hlen); if(!hs) return CURLE_OUT_OF_MEMORY; memcpy(hs->buffer, header, hlen); @@ -336,7 +332,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, } else { failf(data, "Invalid response header"); - free(hs); + curlx_free(hs); } return result; } @@ -417,7 +413,7 @@ CURLcode Curl_headers_cleanup(struct Curl_easy *data) for(e = Curl_llist_head(&data->state.httphdrs); e; e = n) { struct Curl_header_store *hs = Curl_node_elem(e); n = Curl_node_next(e); - free(hs); + curlx_free(hs); } headers_reset(data); return CURLE_OK; diff --git a/lib/hmac.c b/lib/hmac.c index 7842f0601b..4f226e6434 100644 --- a/lib/hmac.c +++ b/lib/hmac.c @@ -33,12 +33,8 @@ #include #include "curl_hmac.h" -#include "curl_memory.h" #include "curlx/warnless.h" -/* The last #include file should be: */ -#include "memdebug.h" - /* * Generic HMAC algorithm. * @@ -62,7 +58,7 @@ Curl_HMAC_init(const struct HMAC_params *hashparams, /* Create HMAC context. */ i = sizeof(*ctxt) + 2 * hashparams->ctxtsize + hashparams->resultlen; - ctxt = malloc(i); + ctxt = curlx_malloc(i); if(!ctxt) return ctxt; @@ -103,7 +99,7 @@ Curl_HMAC_init(const struct HMAC_params *hashparams, return ctxt; fail: - free(ctxt); + curlx_free(ctxt); return NULL; } @@ -130,7 +126,7 @@ int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *output) hashparams->hfinal(output, ctxt->hashctxt1); hashparams->hupdate(ctxt->hashctxt2, output, hashparams->resultlen); hashparams->hfinal(output, ctxt->hashctxt2); - free(ctxt); + curlx_free(ctxt); return 0; } diff --git a/lib/hostip.c b/lib/hostip.c index 58a7712cf4..e81886995e 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -62,10 +62,6 @@ #include "easy_lock.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(CURLRES_SYNCH) && \ defined(HAVE_ALARM) && \ defined(SIGALRM) && \ @@ -451,7 +447,7 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, struct Curl_addrinfo **nodes; infof(data, "Shuffling %i addresses", num_addrs); - nodes = malloc(num_addrs*sizeof(*nodes)); + nodes = curlx_malloc(num_addrs*sizeof(*nodes)); if(nodes) { int i; unsigned int *rnd; @@ -463,7 +459,7 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, nodes[i] = nodes[i-1]->ai_next; } - rnd = malloc(rnd_size); + rnd = curlx_malloc(rnd_size); if(rnd) { /* Fisher-Yates shuffle */ if(Curl_rand(data, (unsigned char *)rnd, rnd_size) == CURLE_OK) { @@ -482,11 +478,11 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, nodes[num_addrs-1]->ai_next = NULL; *addr = nodes[0]; } - free(rnd); + curlx_free(rnd); } else result = CURLE_OUT_OF_MEMORY; - free(nodes); + curlx_free(nodes); } else result = CURLE_OUT_OF_MEMORY; @@ -519,7 +515,7 @@ Curl_dnscache_mk_entry(struct Curl_easy *data, hostlen = strlen(hostname); /* Create a new cache entry */ - dns = calloc(1, sizeof(struct Curl_dns_entry) + hostlen); + dns = curlx_calloc(1, sizeof(struct Curl_dns_entry) + hostlen); if(!dns) return NULL; @@ -609,7 +605,7 @@ static struct Curl_addrinfo *get_localhost6(int port, const char *name) struct sockaddr_in6 sa6; unsigned char ipv6[16]; unsigned short port16 = (unsigned short)(port & 0xffff); - ca = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); + ca = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); if(!ca) return NULL; @@ -658,7 +654,7 @@ static struct Curl_addrinfo *get_localhost(int port, const char *name) return NULL; memcpy(&sa.sin_addr, &ipv4, sizeof(ipv4)); - ca = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); + ca = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1); if(!ca) return NULL; ca->ai_flags = 0; @@ -1178,10 +1174,10 @@ static void dnscache_entry_free(struct Curl_dns_entry *dns) #ifdef USE_HTTPSRR if(dns->hinfo) { Curl_httpsrr_cleanup(dns->hinfo); - free(dns->hinfo); + curlx_free(dns->hinfo); } #endif - free(dns); + curlx_free(dns); } /* diff --git a/lib/hostip4.c b/lib/hostip4.c index d543c1e14b..f01e902fd6 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -50,10 +50,6 @@ #include "curl_share.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef CURLRES_SYNCH @@ -139,7 +135,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, */ int h_errnop; - buf = calloc(1, CURL_HOSTENT_SIZE); + buf = curlx_calloc(1, CURL_HOSTENT_SIZE); if(!buf) return NULL; /* major failure */ /* @@ -253,8 +249,8 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, * Since we do not know how big buffer this particular lookup required, * we cannot realloc down the huge alloc without doing closer analysis of * the returned data. Thus, we always use CURL_HOSTENT_SIZE for every - * name lookup. Fixing this would require an extra malloc() and then - * calling Curl_addrinfo_copy() that subsequent realloc()s down the new + * name lookup. Fixing this would require an extra allocation and then + * calling Curl_addrinfo_copy() that subsequent reallocation down the new * memory area to the actually used amount. */ } @@ -262,7 +258,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, #endif /* HAVE_...BYNAME_R_5 || HAVE_...BYNAME_R_6 || HAVE_...BYNAME_R_3 */ { h = NULL; /* set return code to NULL */ - free(buf); + curlx_free(buf); } #else /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) || HAVE_GETHOSTBYNAME_R */ @@ -280,7 +276,7 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, ai = Curl_he2ai(h, port); if(buf) /* used a *_r() function */ - free(buf); + curlx_free(buf); } #endif diff --git a/lib/hostip6.c b/lib/hostip6.c index 0f628b3fb5..cfba2a5cbf 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -53,10 +53,6 @@ #include "curlx/inet_pton.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef CURLRES_SYNCH #ifdef DEBUG_ADDRINFO diff --git a/lib/hsts.c b/lib/hsts.c index 836481cd4c..22add03957 100644 --- a/lib/hsts.c +++ b/lib/hsts.c @@ -41,10 +41,6 @@ #include "strdup.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define MAX_HSTS_LINE 4095 #define MAX_HSTS_HOSTLEN 2048 #define MAX_HSTS_DATELEN 256 @@ -72,7 +68,7 @@ static time_t hsts_debugtime(void *unused) struct hsts *Curl_hsts_init(void) { - struct hsts *h = calloc(1, sizeof(struct hsts)); + struct hsts *h = curlx_calloc(1, sizeof(struct hsts)); if(h) { Curl_llist_init(&h->list, NULL); } @@ -81,8 +77,8 @@ struct hsts *Curl_hsts_init(void) static void hsts_free(struct stsentry *e) { - free(CURL_UNCONST(e->host)); - free(e); + curlx_free(CURL_UNCONST(e->host)); + curlx_free(e); } void Curl_hsts_cleanup(struct hsts **hp) @@ -96,8 +92,8 @@ void Curl_hsts_cleanup(struct hsts **hp) n = Curl_node_next(e); hsts_free(sts); } - free(h->filename); - free(h); + curlx_free(h->filename); + curlx_free(h); *hp = NULL; } } @@ -116,13 +112,13 @@ static CURLcode hsts_create(struct hsts *h, --hlen; if(hlen) { char *duphost; - struct stsentry *sts = calloc(1, sizeof(struct stsentry)); + struct stsentry *sts = curlx_calloc(1, sizeof(struct stsentry)); if(!sts) return CURLE_OUT_OF_MEMORY; duphost = Curl_memdup0(hostname, hlen); if(!duphost) { - free(sts); + curlx_free(sts); return CURLE_OUT_OF_MEMORY; } @@ -385,7 +381,7 @@ CURLcode Curl_hsts_save(struct Curl_easy *data, struct hsts *h, if(result && tempstore) unlink(tempstore); } - free(tempstore); + curlx_free(tempstore); skipsave: if(data->set.hsts_write) { /* if there is a write callback */ @@ -518,8 +514,8 @@ static CURLcode hsts_load(struct hsts *h, const char *file) /* we need a private copy of the filename so that the hsts cache file name survives an easy handle reset */ - free(h->filename); - h->filename = strdup(file); + curlx_free(h->filename); + h->filename = curlx_strdup(file); if(!h->filename) return CURLE_OUT_OF_MEMORY; diff --git a/lib/http.c b/lib/http.c index 8223c6f0e2..f09d96ee06 100644 --- a/lib/http.c +++ b/lib/http.c @@ -87,10 +87,6 @@ #include "curl_ctype.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Forward declarations. */ @@ -277,7 +273,7 @@ static bool http_header_is_empty(const char *header) /* * Strip off leading and trailing whitespace from the value in the given HTTP - * header line and return a strdup()ed copy in 'valp' - returns an empty + * header line and return a strdup-ed copy in 'valp' - returns an empty * string if the header value consists entirely of whitespace. * * If the header is provided as "name;", ending with a semicolon, it returns a @@ -305,7 +301,7 @@ static CURLcode copy_custom_value(const char *header, char **valp) /* * Strip off leading and trailing whitespace from the value in the given HTTP - * header line and return a strdup()ed copy in 'valp' - returns an empty + * header line and return a strdup-ed copy in 'valp' - returns an empty * string if the header value consists entirely of whitespace. * * This function MUST be used after the header has already been confirmed to @@ -377,18 +373,18 @@ static CURLcode http_output_basic(struct Curl_easy *data, bool proxy) goto fail; } - free(*userp); + curlx_free(*userp); *userp = curl_maprintf("%sAuthorization: Basic %s\r\n", proxy ? "Proxy-" : "", authorization); - free(authorization); + curlx_free(authorization); if(!*userp) { result = CURLE_OUT_OF_MEMORY; goto fail; } fail: - free(out); + curlx_free(out); return result; } @@ -407,7 +403,7 @@ static CURLcode http_output_bearer(struct Curl_easy *data) CURLcode result = CURLE_OK; userp = &data->state.aptr.userpwd; - free(*userp); + curlx_free(*userp); *userp = curl_maprintf("Authorization: Bearer %s\r\n", data->set.str[STRING_BEARER]); @@ -615,8 +611,8 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) /* In case this is GSS auth, the newurl field is already allocated so we must make sure to free it before allocating a new one. As figured out in bug #2284386 */ - free(data->req.newurl); - data->req.newurl = strdup(data->state.url); /* clone URL */ + curlx_free(data->req.newurl); + data->req.newurl = curlx_strdup(data->state.url); /* clone URL */ if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; } @@ -629,7 +625,7 @@ CURLcode Curl_http_auth_act(struct Curl_easy *data) we did not try HEAD or GET */ if((data->state.httpreq != HTTPREQ_GET) && (data->state.httpreq != HTTPREQ_HEAD)) { - data->req.newurl = strdup(data->state.url); /* clone URL */ + data->req.newurl = curlx_strdup(data->state.url); /* clone URL */ if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; data->state.authhost.done = TRUE; @@ -916,8 +912,8 @@ static CURLcode auth_spnego(struct Curl_easy *data, curlnegotiate *negstate = proxy ? &conn->proxy_negotiate_state : &conn->http_negotiate_state; if(!result) { - free(data->req.newurl); - data->req.newurl = strdup(data->state.url); + curlx_free(data->req.newurl); + data->req.newurl = curlx_strdup(data->state.url); if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; data->state.authproblem = FALSE; @@ -1291,7 +1287,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, /* the URL could not be parsed for some reason, but since this is FAKE mode, just duplicate the field as-is */ - follow_url = strdup(newurl); + follow_url = curlx_strdup(newurl); if(!follow_url) return CURLE_OUT_OF_MEMORY; } @@ -1316,13 +1312,13 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, uc = curl_url_get(data->state.uh, CURLUPART_PORT, &portnum, CURLU_DEFAULT_PORT); if(uc) { - free(follow_url); + curlx_free(follow_url); return Curl_uc_to_curlcode(uc); } p = portnum; curlx_str_number(&p, &value, 0xffff); port = (int)value; - free(portnum); + curlx_free(portnum); } if(port != data->info.conn_remote_port) { infof(data, "Clear auth, redirects to port from %u to %u", @@ -1334,7 +1330,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, const struct Curl_handler *p; uc = curl_url_get(data->state.uh, CURLUPART_SCHEME, &scheme, 0); if(uc) { - free(follow_url); + curlx_free(follow_url); return Curl_uc_to_curlcode(uc); } @@ -1344,7 +1340,7 @@ CURLcode Curl_http_follow(struct Curl_easy *data, const char *newurl, data->info.conn_scheme, scheme); clear = TRUE; } - free(scheme); + curlx_free(scheme); } if(clear) { Curl_safefree(data->state.aptr.user); @@ -1917,7 +1913,7 @@ static CURLcode http_useragent(struct Curl_easy *data) with the user-agent string specified, we erase the previously made string here. */ if(Curl_checkheaders(data, STRCONST("User-Agent"))) { - free(data->state.aptr.uagent); + curlx_free(data->state.aptr.uagent); data->state.aptr.uagent = NULL; } return CURLE_OK; @@ -1932,9 +1928,9 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) if(!data->state.this_is_a_follow) { /* Free to avoid leaking memory on multiple requests */ - free(data->state.first_host); + curlx_free(data->state.first_host); - data->state.first_host = strdup(conn->host.name); + data->state.first_host = curlx_strdup(conn->host.name); if(!data->state.first_host) return CURLE_OUT_OF_MEMORY; @@ -1958,7 +1954,7 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) return result; if(!*cookiehost) /* ignore empty data */ - free(cookiehost); + curlx_free(cookiehost); else { /* If the host begins with '[', we start searching for the port after the bracket has been closed */ @@ -1977,7 +1973,7 @@ static CURLcode http_set_aptr_host(struct Curl_easy *data) if(colon) *colon = 0; /* The host must not include an embedded port number */ } - free(aptr->cookiehost); + curlx_free(aptr->cookiehost); aptr->cookiehost = cookiehost; } #endif @@ -2086,7 +2082,7 @@ static CURLcode http_target(struct Curl_easy *data, /* target or URL */ result = curlx_dyn_add(r, data->set.str[STRING_TARGET] ? data->set.str[STRING_TARGET] : url); - free(url); + curlx_free(url); if(result) return result; @@ -2142,7 +2138,7 @@ static CURLcode set_post_reader(struct Curl_easy *data, Curl_HttpReq httpreq) /* Convert the form structure into a mime structure, then keep the conversion */ if(!data->state.formp) { - data->state.formp = calloc(1, sizeof(curl_mimepart)); + data->state.formp = curlx_calloc(1, sizeof(curl_mimepart)); if(!data->state.formp) return CURLE_OUT_OF_MEMORY; Curl_mime_cleanpart(data->state.formp); @@ -2547,7 +2543,7 @@ static CURLcode http_range(struct Curl_easy *data, if(((httpreq == HTTPREQ_GET) || (httpreq == HTTPREQ_HEAD)) && !Curl_checkheaders(data, STRCONST("Range"))) { /* if a line like this was already allocated, free the previous one */ - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); data->state.aptr.rangeline = curl_maprintf("Range: bytes=%s\r\n", data->state.range); if(!data->state.aptr.rangeline) @@ -2557,7 +2553,7 @@ static CURLcode http_range(struct Curl_easy *data, !Curl_checkheaders(data, STRCONST("Content-Range"))) { curl_off_t req_clen = Curl_creader_total_length(data); /* if a line like this was already allocated, free the previous one */ - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); if(data->set.set_resume_from < 0) { /* Upload resume was asked for, but we do not know the size of the @@ -2723,7 +2719,7 @@ static CURLcode http_add_connection_hd(struct Curl_easy *data, return result; result = curlx_dyn_addf(req, "%s%s", sep, value); sep = ", "; - free(value); + curlx_free(value); break; /* leave, having added 1st one */ } } @@ -3000,7 +2996,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done) } result = Curl_http_output_auth(data, data->conn, method, httpreq, (pq ? pq : data->state.up.path), FALSE); - free(pq); + curlx_free(pq); } if(result) goto out; @@ -3245,9 +3241,9 @@ static CURLcode http_header_c(struct Curl_easy *data, return CURLE_OUT_OF_MEMORY; if(!*contenttype) /* ignore empty data */ - free(contenttype); + curlx_free(contenttype); else { - free(data->info.contenttype); + curlx_free(data->info.contenttype); data->info.contenttype = contenttype; } return CURLE_OK; @@ -3333,14 +3329,14 @@ static CURLcode http_header_l(struct Curl_easy *data, if(!*location || (data->req.location && !strcmp(data->req.location, location))) { /* ignore empty header, or exact repeat of a previous one */ - free(location); + curlx_free(location); return CURLE_OK; } else { /* has value and is not an exact repeat */ if(data->req.location) { failf(data, "Multiple Location headers"); - free(location); + curlx_free(location); return CURLE_WEIRD_SERVER_REPLY; } data->req.location = location; @@ -3349,7 +3345,7 @@ static CURLcode http_header_l(struct Curl_easy *data, data->set.http_follow_mode) { CURLcode result; DEBUGASSERT(!data->req.newurl); - data->req.newurl = strdup(data->req.location); /* clone */ + data->req.newurl = curlx_strdup(data->req.location); /* clone */ if(!data->req.newurl) return CURLE_OUT_OF_MEMORY; @@ -3407,7 +3403,7 @@ static CURLcode http_header_p(struct Curl_easy *data, CURLcode result = auth ? CURLE_OK : CURLE_OUT_OF_MEMORY; if(!result) { result = Curl_http_input_auth(data, TRUE, auth); - free(auth); + curlx_free(auth); } return result; } @@ -3426,7 +3422,7 @@ static CURLcode http_header_p(struct Curl_easy *data, negdata->havenoauthpersist = TRUE; infof(data, "Negotiate: noauthpersist -> %d, header part: %s", negdata->noauthpersist, persistentauth); - free(persistentauth); + curlx_free(persistentauth); } } #endif @@ -3587,7 +3583,7 @@ static CURLcode http_header_w(struct Curl_easy *data, result = CURLE_OUT_OF_MEMORY; else { result = Curl_http_input_auth(data, FALSE, auth); - free(auth); + curlx_free(auth); } } return result; @@ -4065,7 +4061,7 @@ static CURLcode http_on_response(struct Curl_easy *data, data->state.disableexpect = TRUE; Curl_req_abort_sending(data); DEBUGASSERT(!data->req.newurl); - data->req.newurl = strdup(data->state.url); + data->req.newurl = curlx_strdup(data->state.url); if(!data->req.newurl) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -4533,7 +4529,7 @@ CURLcode Curl_http_req_make(struct httpreq **preq, DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req) + m_len); + req = curlx_calloc(1, sizeof(*req) + m_len); if(!req) goto out; #if defined(__GNUC__) && __GNUC__ >= 13 @@ -4606,8 +4602,8 @@ static CURLcode req_assign_url_authority(struct httpreq *req, CURLU *url) } req->authority = curlx_dyn_ptr(&buf); out: - free(host); - free(port); + curlx_free(host); + curlx_free(port); if(result) curlx_dyn_free(&buf); return result; @@ -4645,8 +4641,8 @@ static CURLcode req_assign_url_path(struct httpreq *req, CURLU *url) result = CURLE_OK; out: - free(path); - free(query); + curlx_free(path); + curlx_free(query); if(result) curlx_dyn_free(&buf); return result; @@ -4662,7 +4658,7 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, DEBUGASSERT(method && m_len); - req = calloc(1, sizeof(*req) + m_len); + req = curlx_calloc(1, sizeof(*req) + m_len); if(!req) goto out; memcpy(req->method, method, m_len); @@ -4671,7 +4667,7 @@ CURLcode Curl_http_req_make2(struct httpreq **preq, if(uc && uc != CURLUE_NO_SCHEME) goto out; if(!req->scheme && scheme_default) { - req->scheme = strdup(scheme_default); + req->scheme = curlx_strdup(scheme_default); if(!req->scheme) goto out; } @@ -4697,12 +4693,12 @@ out: void Curl_http_req_free(struct httpreq *req) { if(req) { - free(req->scheme); - free(req->authority); - free(req->path); + curlx_free(req->scheme); + curlx_free(req->authority); + curlx_free(req->path); Curl_dynhds_free(&req->headers); Curl_dynhds_free(&req->trailers); - free(req); + curlx_free(req); } } @@ -4840,13 +4836,13 @@ CURLcode Curl_http_resp_make(struct http_resp **presp, struct http_resp *resp; CURLcode result = CURLE_OUT_OF_MEMORY; - resp = calloc(1, sizeof(*resp)); + resp = curlx_calloc(1, sizeof(*resp)); if(!resp) goto out; resp->status = status; if(description) { - resp->description = strdup(description); + resp->description = curlx_strdup(description); if(!resp->description) goto out; } @@ -4864,12 +4860,12 @@ out: void Curl_http_resp_free(struct http_resp *resp) { if(resp) { - free(resp->description); + curlx_free(resp->description); Curl_dynhds_free(&resp->headers); Curl_dynhds_free(&resp->trailers); if(resp->prev) Curl_http_resp_free(resp->prev); - free(resp); + curlx_free(resp); } } diff --git a/lib/http1.c b/lib/http1.c index b1d8097636..0a80fedfc7 100644 --- a/lib/http1.c +++ b/lib/http1.c @@ -32,10 +32,6 @@ #include "http1.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define H1_MAX_URL_LEN (8*1024) diff --git a/lib/http2.c b/lib/http2.c index 2e8649c105..baaefd439d 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -48,10 +48,6 @@ #include "curlx/warnless.h" #include "headers.h" -/* The last 3 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if (NGHTTP2_VERSION_NUM < 0x010c00) #error too old nghttp2 version, upgrade! #endif @@ -168,7 +164,7 @@ static void cf_h2_ctx_free(struct cf_h2_ctx *ctx) Curl_uint32_hash_destroy(&ctx->streams); memset(ctx, 0, sizeof(*ctx)); } - free(ctx); + curlx_free(ctx); } static void cf_h2_ctx_close(struct cf_h2_ctx *ctx) @@ -276,7 +272,7 @@ static struct h2_stream_ctx *h2_stream_ctx_create(struct cf_h2_ctx *ctx) struct h2_stream_ctx *stream; (void)ctx; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return NULL; @@ -299,7 +295,7 @@ static void free_push_headers(struct h2_stream_ctx *stream) { size_t i; for(i = 0; i < stream->push_headers_used; i++) - free(stream->push_headers[i]); + curlx_free(stream->push_headers[i]); Curl_safefree(stream->push_headers); stream->push_headers_used = 0; } @@ -310,7 +306,7 @@ static void h2_stream_ctx_free(struct h2_stream_ctx *stream) Curl_h1_req_parse_free(&stream->h1); Curl_dynhds_free(&stream->resp_trailers); free_push_headers(stream); - free(stream); + curlx_free(stream); } static void h2_stream_hash_free(unsigned int id, void *stream) @@ -952,7 +948,7 @@ fail: return rc; if(data->state.url_alloc) - free(data->state.url); + curlx_free(data->state.url); data->state.url_alloc = TRUE; data->state.url = url; return 0; @@ -1642,15 +1638,15 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, stream_id, NGHTTP2_PROTOCOL_ERROR); rc = NGHTTP2_ERR_CALLBACK_FAILURE; } - free(check); + curlx_free(check); if(rc) return rc; } if(!stream->push_headers) { stream->push_headers_alloc = 10; - stream->push_headers = malloc(stream->push_headers_alloc * - sizeof(char *)); + stream->push_headers = curlx_malloc(stream->push_headers_alloc * + sizeof(char *)); if(!stream->push_headers) return NGHTTP2_ERR_CALLBACK_FAILURE; stream->push_headers_used = 0; @@ -1665,8 +1661,8 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, return NGHTTP2_ERR_CALLBACK_FAILURE; } stream->push_headers_alloc *= 2; - headp = realloc(stream->push_headers, - stream->push_headers_alloc * sizeof(char *)); + headp = curlx_realloc(stream->push_headers, + stream->push_headers_alloc * sizeof(char *)); if(!headp) { free_push_headers(stream); return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -1859,7 +1855,7 @@ CURLcode Curl_http2_request_upgrade(struct dynbuf *req, "Upgrade: %s\r\n" "HTTP2-Settings: %s\r\n", NGHTTP2_CLEARTEXT_PROTO_VERSION_ID, base64); - free(base64); + curlx_free(base64); k->upgr101 = UPGR101_H2; data->conn->bits.upgrade_in_progress = TRUE; @@ -2881,7 +2877,7 @@ static CURLcode http2_cfilter_add(struct Curl_cfilter **pcf, CURLcode result = CURLE_OUT_OF_MEMORY; DEBUGASSERT(data->conn); - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; cf_h2_ctx_init(ctx, via_h1_upgrade); @@ -2909,7 +2905,7 @@ static CURLcode http2_cfilter_insert_after(struct Curl_cfilter *cf, CURLcode result = CURLE_OUT_OF_MEMORY; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) goto out; cf_h2_ctx_init(ctx, via_h1_upgrade); diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index d3d4760be7..0ef18b6fea 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -39,10 +39,6 @@ #include -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #include "slist.h" #define HMAC_SHA256(k, kl, d, dl, o) \ @@ -210,12 +206,12 @@ static CURLcode merge_duplicate_headers(struct curl_slist *head) if(result) return result; - free(curr->data); + curlx_free(curr->data); curr->data = curlx_dyn_ptr(&buf); curr->next = next->next; - free(next->data); - free(next); + curlx_free(next->data); + curlx_free(next); } else { curr = curr->next; @@ -269,7 +265,7 @@ static CURLcode make_headers(struct Curl_easy *data, if(fullhost) head = Curl_slist_append_nodup(NULL, fullhost); if(!head) { - free(fullhost); + curlx_free(fullhost); goto fail; } } @@ -307,13 +303,13 @@ static CURLcode make_headers(struct Curl_easy *data, ; if(!*ptr && ptr != sep + 1) /* a value of whitespace only */ continue; - dupdata = strdup(l->data); + dupdata = curlx_strdup(l->data); if(!dupdata) goto fail; dupdata[sep - l->data] = ':'; tmp_head = Curl_slist_append_nodup(head, dupdata); if(!tmp_head) { - free(dupdata); + curlx_free(dupdata); goto fail; } head = tmp_head; @@ -964,7 +960,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data) Curl_strntoupper(&auth_headers[sizeof("Authorization: ") - 1], curlx_str(&provider0), curlx_strlen(&provider0)); - free(data->state.aptr.userpwd); + curlx_free(data->state.aptr.userpwd); data->state.aptr.userpwd = auth_headers; data->state.authhost.done = TRUE; result = CURLE_OK; @@ -974,12 +970,12 @@ fail: curlx_dyn_free(&canonical_path); curlx_dyn_free(&canonical_headers); curlx_dyn_free(&signed_headers); - free(canonical_request); - free(request_type); - free(credential_scope); - free(str_to_sign); - free(secret); - free(date_header); + curlx_free(canonical_request); + curlx_free(request_type); + curlx_free(credential_scope); + curlx_free(str_to_sign); + curlx_free(secret); + curlx_free(date_header); return result; } diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 005d34e7b9..9d0a0b324c 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -36,10 +36,6 @@ #include "curlx/strparse.h" #include "curlx/warnless.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Chunk format (simplified): * diff --git a/lib/http_digest.c b/lib/http_digest.c index 097c81fd71..2ca1a12d5d 100644 --- a/lib/http_digest.c +++ b/lib/http_digest.c @@ -32,10 +32,6 @@ #include "http_digest.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Test example headers: WWW-Authenticate: Digest realm="testrealm", nonce="1053604598" @@ -152,20 +148,20 @@ CURLcode Curl_output_digest(struct Curl_easy *data, } } if(!tmp) - path = (unsigned char *)strdup((const char *) uripath); + path = (unsigned char *)curlx_strdup((const char *) uripath); if(!path) return CURLE_OUT_OF_MEMORY; result = Curl_auth_create_digest_http_message(data, userp, passwdp, request, path, digest, &response, &len); - free(path); + curlx_free(path); if(result) return result; *allocuserpwd = curl_maprintf("%sAuthorization: Digest %s\r\n", proxy ? "Proxy-" : "", response); - free(response); + curlx_free(response); if(!*allocuserpwd) return CURLE_OUT_OF_MEMORY; diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c index 136cb07641..fc80f80fa3 100644 --- a/lib/http_negotiate.c +++ b/lib/http_negotiate.c @@ -34,10 +34,6 @@ #include "vtls/vtls.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void http_auth_nego_reset(struct connectdata *conn, struct negotiatedata *neg_ctx, @@ -223,16 +219,16 @@ CURLcode Curl_output_negotiate(struct Curl_easy *data, if(proxy) { #ifndef CURL_DISABLE_PROXY - free(data->state.aptr.proxyuserpwd); + curlx_free(data->state.aptr.proxyuserpwd); data->state.aptr.proxyuserpwd = userp; #endif } else { - free(data->state.aptr.userpwd); + curlx_free(data->state.aptr.userpwd); data->state.aptr.userpwd = userp; } - free(base64); + curlx_free(base64); if(!userp) { return CURLE_OUT_OF_MEMORY; diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c index 8cb6403fdb..2856745c34 100644 --- a/lib/http_ntlm.c +++ b/lib/http_ntlm.c @@ -49,10 +49,6 @@ #include "curl_sspi.h" #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - CURLcode Curl_input_ntlm(struct Curl_easy *data, bool proxy, /* if proxy or not */ const char *header) /* rest of the www-authenticate: @@ -208,11 +204,11 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg), Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { - free(*allocuserpwd); + curlx_free(*allocuserpwd); *allocuserpwd = curl_maprintf("%sAuthorization: NTLM %s\r\n", proxy ? "Proxy-" : "", base64); - free(base64); + curlx_free(base64); if(!*allocuserpwd) result = CURLE_OUT_OF_MEMORY; } @@ -227,11 +223,11 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy) result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg), Curl_bufref_len(&ntlmmsg), &base64, &len); if(!result) { - free(*allocuserpwd); + curlx_free(*allocuserpwd); *allocuserpwd = curl_maprintf("%sAuthorization: NTLM %s\r\n", proxy ? "Proxy-" : "", base64); - free(base64); + curlx_free(base64); if(!*allocuserpwd) result = CURLE_OUT_OF_MEMORY; else { diff --git a/lib/http_proxy.c b/lib/http_proxy.c index 9bde118baf..21f0cc6211 100644 --- a/lib/http_proxy.c +++ b/lib/http_proxy.c @@ -44,10 +44,6 @@ #include "vauth/vauth.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode dynhds_add_custom(struct Curl_easy *data, bool is_connect, int httpversion, struct dynhds *hds) @@ -270,7 +266,7 @@ out: Curl_http_req_free(req); req = NULL; } - free(authority); + curlx_free(authority); *preq = req; return result; } @@ -386,7 +382,7 @@ static void http_proxy_cf_destroy(struct Curl_cfilter *cf, (void)data; CURL_TRC_CF(data, cf, "destroy"); - free(ctx); + curlx_free(ctx); } static void http_proxy_cf_close(struct Curl_cfilter *cf, @@ -425,7 +421,7 @@ CURLcode Curl_cf_http_proxy_insert_after(struct Curl_cfilter *cf_at, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -437,7 +433,7 @@ CURLcode Curl_cf_http_proxy_insert_after(struct Curl_cfilter *cf_at, Curl_conn_cf_insert_after(cf_at, cf); out: - free(ctx); + curlx_free(ctx); return result; } diff --git a/lib/httpsrr.c b/lib/httpsrr.c index 0cf5b131bd..34d081b502 100644 --- a/lib/httpsrr.c +++ b/lib/httpsrr.c @@ -33,10 +33,6 @@ #include "sendf.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode httpsrr_decode_alpn(const uint8_t *cp, size_t len, unsigned char *alpns) { @@ -97,7 +93,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_IPV4: /* addr4 list */ if(!vlen || (vlen & 3)) /* the size must be 4-byte aligned */ return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->ipv4hints); + curlx_free(hi->ipv4hints); hi->ipv4hints = Curl_memdup(val, vlen); if(!hi->ipv4hints) return CURLE_OUT_OF_MEMORY; @@ -107,7 +103,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_ECH: if(!vlen) return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->echconfiglist); + curlx_free(hi->echconfiglist); hi->echconfiglist = Curl_memdup(val, vlen); if(!hi->echconfiglist) return CURLE_OUT_OF_MEMORY; @@ -117,7 +113,7 @@ CURLcode Curl_httpsrr_set(struct Curl_easy *data, case HTTPS_RR_CODE_IPV6: /* addr6 list */ if(!vlen || (vlen & 15)) /* the size must be 16-byte aligned */ return CURLE_BAD_FUNCTION_ARGUMENT; - free(hi->ipv6hints); + curlx_free(hi->ipv6hints); hi->ipv6hints = Curl_memdup(val, vlen); if(!hi->ipv6hints) return CURLE_OUT_OF_MEMORY; @@ -189,8 +185,8 @@ CURLcode Curl_httpsrr_from_ares(struct Curl_easy *data, is in ServiceMode */ target = ares_dns_rr_get_str(rr, ARES_RR_HTTPS_TARGET); if(target && target[0]) { - free(hinfo->target); - hinfo->target = strdup(target); + curlx_free(hinfo->target); + hinfo->target = curlx_strdup(target); if(!hinfo->target) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/idn.c b/lib/idn.c index 7e324db6c4..1c404f6543 100644 --- a/lib/idn.c +++ b/lib/idn.c @@ -45,10 +45,6 @@ #endif #endif /* USE_LIBIDN2 */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* for macOS and iOS targets */ #ifdef USE_APPLE_IDN #include @@ -108,7 +104,7 @@ static CURLcode mac_idn_to_ascii(const char *in, char **out) buffer, sizeof(buffer) - 1, &info, &err); uidna_close(idna); if(!U_FAILURE(err) && !info.errors) { - *out = strdup(buffer); + *out = curlx_strdup(buffer); if(*out) return CURLE_OK; else @@ -136,7 +132,7 @@ static CURLcode mac_ascii_to_idn(const char *in, char **out) sizeof(buffer) - 1, &info, &err); uidna_close(idna); if(!U_FAILURE(err)) { - *out = strdup(buffer); + *out = curlx_strdup(buffer); if(*out) return CURLE_OK; else @@ -179,7 +175,7 @@ static CURLcode win32_idn_to_ascii(const char *in, char **out) if(chars) { char *mstr = curlx_convert_wchar_to_UTF8(punycode); if(mstr) { - *out = strdup(mstr); + *out = curlx_strdup(mstr); curlx_unicodefree(mstr); if(!*out) return CURLE_OUT_OF_MEMORY; @@ -209,7 +205,7 @@ static CURLcode win32_ascii_to_idn(const char *in, char **output) /* 'chars' is "the number of characters retrieved" */ char *mstr = curlx_convert_wchar_to_UTF8(idn); if(mstr) { - out = strdup(mstr); + out = curlx_strdup(mstr); curlx_unicodefree(mstr); if(!out) return CURLE_OUT_OF_MEMORY; @@ -314,7 +310,7 @@ CURLcode Curl_idn_decode(const char *input, char **output) CURLcode result = idn_decode(input, &d); #ifdef USE_LIBIDN2 if(!result) { - char *c = strdup(d); + char *c = curlx_strdup(d); idn2_free(d); if(c) d = c; @@ -325,7 +321,7 @@ CURLcode Curl_idn_decode(const char *input, char **output) if(!result) { if(!d[0]) { /* ended up zero length, not acceptable */ result = CURLE_URL_MALFORMAT; - free(d); + curlx_free(d); } else *output = d; @@ -339,7 +335,7 @@ CURLcode Curl_idn_encode(const char *puny, char **output) CURLcode result = idn_encode(puny, &d); #ifdef USE_LIBIDN2 if(!result) { - char *c = strdup(d); + char *c = curlx_strdup(d); idn2_free(d); if(c) d = c; diff --git a/lib/if2ip.c b/lib/if2ip.c index 79b0599106..c2b8aafc4d 100644 --- a/lib/if2ip.c +++ b/lib/if2ip.c @@ -55,10 +55,6 @@ #include "curlx/inet_ntop.h" #include "if2ip.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* ------------------------------------------------------------------ */ #ifdef USE_IPV6 diff --git a/lib/imap.c b/lib/imap.c index af9b124d1e..d093e46d33 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -78,10 +78,6 @@ #include "curlx/warnless.h" #include "curl_ctype.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_IMAP_EASY "meta:proto:imap:easy" @@ -617,8 +613,8 @@ static CURLcode imap_perform_login(struct Curl_easy *data, result = imap_sendf(data, imapc, "LOGIN %s %s", user ? user : "", passwd ? passwd : ""); - free(user); - free(passwd); + curlx_free(user); + curlx_free(passwd); if(!result) imap_state(data, imapc, IMAP_LOGIN); @@ -751,14 +747,14 @@ static CURLcode imap_perform_list(struct Curl_easy *data, else { /* Make sure the mailbox is in the correct atom format if necessary */ char *mailbox = imap->mailbox ? imap_atom(imap->mailbox, TRUE) - : strdup(""); + : curlx_strdup(""); if(!mailbox) return CURLE_OUT_OF_MEMORY; /* Send the LIST command */ result = imap_sendf(data, imapc, "LIST \"%s\" *", mailbox); - free(mailbox); + curlx_free(mailbox); } if(!result) @@ -797,7 +793,7 @@ static CURLcode imap_perform_select(struct Curl_easy *data, /* Send the SELECT command */ result = imap_sendf(data, imapc, "SELECT %s", mailbox); - free(mailbox); + curlx_free(mailbox); if(!result) imap_state(data, imapc, IMAP_SELECT); @@ -947,7 +943,7 @@ static CURLcode imap_perform_append(struct Curl_easy *data, cleanup: curlx_dyn_free(&flags); - free(mailbox); + curlx_free(mailbox); if(!result) imap_state(data, imapc, IMAP_APPEND); @@ -1338,7 +1334,7 @@ static CURLcode imap_state_select_resp(struct Curl_easy *data, else { /* Note the currently opened mailbox on this connection */ DEBUGASSERT(!imapc->mailbox); - imapc->mailbox = strdup(imap->mailbox); + imapc->mailbox = curlx_strdup(imap->mailbox); if(!imapc->mailbox) return CURLE_OUT_OF_MEMORY; @@ -1967,7 +1963,7 @@ static void imap_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; imap_easy_reset(imap); - free(imap); + curlx_free(imap); } static void imap_conn_dtor(void *key, size_t klen, void *entry) @@ -1978,7 +1974,7 @@ static void imap_conn_dtor(void *key, size_t klen, void *entry) Curl_pp_disconnect(&imapc->pp); curlx_dyn_free(&imapc->dyn); Curl_safefree(imapc->mailbox); - free(imapc); + curlx_free(imapc); } static CURLcode imap_setup_connection(struct Curl_easy *data, @@ -1988,7 +1984,7 @@ static CURLcode imap_setup_connection(struct Curl_easy *data, struct pingpong *pp; struct IMAP *imap; - imapc = calloc(1, sizeof(*imapc)); + imapc = curlx_calloc(1, sizeof(*imapc)); if(!imapc) return CURLE_OUT_OF_MEMORY; @@ -2005,7 +2001,7 @@ static CURLcode imap_setup_connection(struct Curl_easy *data, if(Curl_conn_meta_set(conn, CURL_META_IMAP_CONN, imapc, imap_conn_dtor)) return CURLE_OUT_OF_MEMORY; - imap = calloc(1, sizeof(struct IMAP)); + imap = curlx_calloc(1, sizeof(struct IMAP)); if(!imap || Curl_meta_set(data, CURL_META_IMAP_EASY, imap, imap_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -2078,7 +2074,7 @@ static char *imap_atom(const char *str, bool escape_only) nclean = strcspn(str, "() {%*]\\\""); if(len == nclean) /* nothing to escape, return a strdup */ - return strdup(str); + return curlx_strdup(str); curlx_dyn_init(&line, 2000); @@ -2258,7 +2254,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, result = Curl_urldecode(begin, ptr - begin, &value, &valuelen, REJECT_CTRL); if(result) { - free(name); + curlx_free(name); return result; } @@ -2279,7 +2275,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, imap->uidvalidity = (unsigned int)num; imap->uidvalidity_set = TRUE; } - free(value); + curlx_free(value); } else if(curl_strequal(name, "UID") && !imap->uid) { imap->uid = value; @@ -2294,15 +2290,15 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data, imap->partial = value; } else { - free(name); - free(value); + curlx_free(name); + curlx_free(value); return CURLE_URL_MALFORMAT; } } else /* blank? */ - free(value); - free(name); + curlx_free(value); + curlx_free(name); } /* Does the URL contain a query parameter? Only valid when we have a mailbox @@ -2346,7 +2342,7 @@ static CURLcode imap_parse_custom_request(struct Curl_easy *data, params++; if(*params) { - imap->custom_params = strdup(params); + imap->custom_params = curlx_strdup(params); imap->custom[params - imap->custom] = '\0'; if(!imap->custom_params) diff --git a/lib/ldap.c b/lib/ldap.c index 7f2af36643..6c62070385 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -94,10 +94,6 @@ #include "curlx/base64.h" #include "connect.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_WIN32_LDAP #define FREE_ON_WINLDAP(x) curlx_unicodefree(x) #define curl_ldap_num_t ULONG @@ -642,7 +638,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) if(val_b64_sz > 0) { result = Curl_client_write(data, CLIENTWRITE_BODY, val_b64, val_b64_sz); - free(val_b64); + curlx_free(val_b64); if(result) { ldap_value_free_len(vals); FREE_ON_WINLDAP(attr); @@ -809,15 +805,15 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_host = conn->host.name; /* Duplicate the path */ - p = path = strdup(data->state.up.path + 1); + p = path = curlx_strdup(data->state.up.path + 1); if(!path) return LDAP_NO_MEMORY; /* Duplicate the query if present */ if(data->state.up.query) { - q = query = strdup(data->state.up.query); + q = query = curlx_strdup(data->state.up.query); if(!query) { - free(path); + curlx_free(path); return LDAP_NO_MEMORY; } } @@ -843,7 +839,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_dn = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_dn) { rc = LDAP_NO_MEMORY; @@ -870,9 +866,9 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, /* Allocate our array (+1 for the NULL entry) */ #ifdef USE_WIN32_LDAP - ludp->lud_attrs = calloc(count + 1, sizeof(TCHAR *)); + ludp->lud_attrs = curlx_calloc(count + 1, sizeof(TCHAR *)); #else - ludp->lud_attrs = calloc(count + 1, sizeof(char *)); + ludp->lud_attrs = curlx_calloc(count + 1, sizeof(char *)); #endif if(!ludp->lud_attrs) { rc = LDAP_NO_MEMORY; @@ -902,7 +898,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_attrs[i] = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_attrs[i]) { rc = LDAP_NO_MEMORY; @@ -966,7 +962,7 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, ludp->lud_filter = curlx_convert_UTF8_to_tchar(unescaped); /* Free the unescaped string as we are done with it */ - free(unescaped); + curlx_free(unescaped); if(!ludp->lud_filter) { rc = LDAP_NO_MEMORY; @@ -986,8 +982,8 @@ static curl_ldap_num_t ldap_url_parse2_low(struct Curl_easy *data, } quit: - free(path); - free(query); + curlx_free(path); + curlx_free(query); return rc; } @@ -996,7 +992,7 @@ static curl_ldap_num_t ldap_url_parse_low(struct Curl_easy *data, const struct connectdata *conn, LDAPURLDesc **ludpp) { - LDAPURLDesc *ludp = calloc(1, sizeof(*ludp)); + LDAPURLDesc *ludp = curlx_calloc(1, sizeof(*ludp)); curl_ldap_num_t rc; *ludpp = NULL; @@ -1021,8 +1017,8 @@ static void ldap_free_urldesc_low(LDAPURLDesc *ludp) curlx_unicodefree(ludp->lud_dn); curlx_unicodefree(ludp->lud_filter); #else - free(ludp->lud_dn); - free(ludp->lud_filter); + curlx_free(ludp->lud_dn); + curlx_free(ludp->lud_filter); #endif if(ludp->lud_attrs) { @@ -1031,13 +1027,13 @@ static void ldap_free_urldesc_low(LDAPURLDesc *ludp) #ifdef USE_WIN32_LDAP curlx_unicodefree(ludp->lud_attrs[i]); #else - free(ludp->lud_attrs[i]); + curlx_free(ludp->lud_attrs[i]); #endif } - free(ludp->lud_attrs); + curlx_free(ludp->lud_attrs); } - free(ludp); + curlx_free(ludp); } #endif /* !HAVE_LDAP_URL_PARSE */ diff --git a/lib/llist.c b/lib/llist.c index c9a7d4a8a7..ebcda82a04 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -27,10 +27,6 @@ #include #include "llist.h" -#include "curl_memory.h" - -/* this must be the last include file */ -#include "memdebug.h" #ifdef DEBUGBUILD #define LLISTINIT 0x100cc001 /* random pattern */ diff --git a/lib/md4.c b/lib/md4.c index 0cc62f8152..7929e57f65 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -71,10 +71,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(USE_WOLFSSL) && !defined(WOLFSSL_NO_MD4) diff --git a/lib/md5.c b/lib/md5.c index 4b38bb070b..a579b02c63 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -81,10 +81,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_GNUTLS typedef struct md5_ctx my_md5_ctx; @@ -604,23 +600,23 @@ struct MD5_context *Curl_MD5_init(const struct MD5_params *md5params) struct MD5_context *ctxt; /* Create MD5 context */ - ctxt = malloc(sizeof(*ctxt)); + ctxt = curlx_malloc(sizeof(*ctxt)); if(!ctxt) return ctxt; - ctxt->md5_hashctx = malloc(md5params->md5_ctxtsize); + ctxt->md5_hashctx = curlx_malloc(md5params->md5_ctxtsize); if(!ctxt->md5_hashctx) { - free(ctxt); + curlx_free(ctxt); return NULL; } ctxt->md5_hash = md5params; if((*md5params->md5_init_func)(ctxt->md5_hashctx)) { - free(ctxt->md5_hashctx); - free(ctxt); + curlx_free(ctxt->md5_hashctx); + curlx_free(ctxt); return NULL; } @@ -640,8 +636,8 @@ CURLcode Curl_MD5_final(struct MD5_context *context, unsigned char *result) { (*context->md5_hash->md5_final_func)(result, context->md5_hashctx); - free(context->md5_hashctx); - free(context); + curlx_free(context->md5_hashctx); + curlx_free(context); return CURLE_OK; } diff --git a/lib/memdebug.c b/lib/memdebug.c index 1121dc26f5..f5b88731ee 100644 --- a/lib/memdebug.c +++ b/lib/memdebug.c @@ -35,10 +35,6 @@ #include "backtrace.h" #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - struct memdebug { size_t size; union { diff --git a/lib/memdebug.h b/lib/memdebug.h deleted file mode 100644 index c2b7fad952..0000000000 --- a/lib/memdebug.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef HEADER_CURL_MEMDEBUG_H -#define HEADER_CURL_MEMDEBUG_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , 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 - * - ***************************************************************************/ - -/* - * CAUTION: this header is designed to work when included by the app-side - * as well as the library. Do not mix with library internals! - */ - -#ifdef CURLDEBUG - -/* Set this symbol on the command-line, recompile all lib-sources */ -#undef strdup -#define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) -#undef malloc -#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) -#undef calloc -#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) -#undef realloc -#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__) -#undef free -#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__) - -#ifdef _WIN32 -#undef Curl_tcsdup -#ifdef UNICODE -#define Curl_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__) -#else -#define Curl_tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) -#endif -#endif /* _WIN32 */ - -#endif /* CURLDEBUG */ -#endif /* HEADER_CURL_MEMDEBUG_H */ diff --git a/lib/mime.c b/lib/mime.c index b1f432c0b0..7ebe47315d 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -50,10 +50,6 @@ struct Curl_easy; #include "slist.h" #include "curlx/dynbuf.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 # ifndef R_OK # define R_OK 4 @@ -357,13 +353,13 @@ static char *strippath(const char *fullfile) { char *filename; char *base; - filename = strdup(fullfile); /* duplicate since basename() may ruin the - buffer it works on */ + filename = curlx_strdup(fullfile); /* duplicate since basename() may ruin + the buffer it works on */ if(!filename) return NULL; - base = strdup(basename(filename)); + base = curlx_strdup(basename(filename)); - free(filename); /* free temporary buffer */ + curlx_free(filename); /* free temporary buffer */ return base; /* returns an allocated string or NULL ! */ } @@ -1190,9 +1186,9 @@ void curl_mime_free(curl_mime *mime) part = mime->firstpart; mime->firstpart = part->nextpart; Curl_mime_cleanpart(part); - free(part); + curlx_free(part); } - free(mime); + curlx_free(mime); } } @@ -1282,7 +1278,7 @@ curl_mime *curl_mime_init(void *easy) { curl_mime *mime; - mime = (curl_mime *) malloc(sizeof(*mime)); + mime = (curl_mime *)curlx_malloc(sizeof(*mime)); if(mime) { mime->parent = NULL; @@ -1294,7 +1290,7 @@ curl_mime *curl_mime_init(void *easy) (unsigned char *) &mime->boundary[MIME_BOUNDARY_DASHES], MIME_RAND_BOUNDARY_CHARS + 1)) { /* failed to get random separator, bail out */ - free(mime); + curlx_free(mime); return NULL; } mimesetstate(&mime->state, MIMESTATE_BEGIN, NULL); @@ -1319,7 +1315,7 @@ curl_mimepart *curl_mime_addpart(curl_mime *mime) if(!mime) return NULL; - part = (curl_mimepart *) malloc(sizeof(*part)); + part = (curl_mimepart *)curlx_malloc(sizeof(*part)); if(part) { Curl_mime_initpart(part); @@ -1345,7 +1341,7 @@ CURLcode curl_mime_name(curl_mimepart *part, const char *name) Curl_safefree(part->name); if(name) { - part->name = strdup(name); + part->name = curlx_strdup(name); if(!part->name) return CURLE_OUT_OF_MEMORY; } @@ -1362,7 +1358,7 @@ CURLcode curl_mime_filename(curl_mimepart *part, const char *filename) Curl_safefree(part->filename); if(filename) { - part->filename = strdup(filename); + part->filename = curlx_strdup(filename); if(!part->filename) return CURLE_OUT_OF_MEMORY; } @@ -1415,7 +1411,7 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) if(curlx_stat(filename, &sbuf)) result = CURLE_READ_ERROR; else { - part->data = strdup(filename); + part->data = curlx_strdup(filename); if(!part->data) result = CURLE_OUT_OF_MEMORY; else { @@ -1438,7 +1434,7 @@ CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename) result = CURLE_OUT_OF_MEMORY; else { result = curl_mime_filename(part, base); - free(base); + curlx_free(base); } } } @@ -1455,7 +1451,7 @@ CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype) Curl_safefree(part->mimetype); if(mimetype) { - part->mimetype = strdup(mimetype); + part->mimetype = curlx_strdup(mimetype); if(!part->mimetype) return CURLE_OUT_OF_MEMORY; } @@ -1696,7 +1692,7 @@ CURLcode Curl_mime_add_header(struct curl_slist **slp, const char *fmt, ...) if(hdr) *slp = hdr; else - free(s); + curlx_free(s); } return hdr ? CURLE_OK : CURLE_OUT_OF_MEMORY; diff --git a/lib/mprintf.c b/lib/mprintf.c index 176f8a3e4b..046917aeb5 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -27,10 +27,6 @@ #include "curl_printf.h" #include "curlx/strparse.h" -#include "curl_memory.h" -/* The last #include file should be: */ -#include "memdebug.h" - #ifdef HAVE_LONGLONG # define LONG_LONG_TYPE long long # define HAVE_LONG_LONG_TYPE @@ -1177,7 +1173,7 @@ char *curl_mvaprintf(const char *format, va_list ap_save) } if(curlx_dyn_len(info.b)) return curlx_dyn_ptr(info.b); - return strdup(""); + return curlx_strdup(""); } char *curl_maprintf(const char *format, ...) diff --git a/lib/mqtt.c b/lib/mqtt.c index 9cbe800ded..a8975d5391 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -40,10 +40,6 @@ #include "multiif.h" #include "rand.h" -/* The last 2 #includes file should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* first byte is command. second byte is for flags. */ #define MQTT_MSG_CONNECT 0x10 @@ -146,14 +142,14 @@ static void mqtt_easy_dtor(void *key, size_t klen, void *entry) (void)klen; curlx_dyn_free(&mq->sendbuf); curlx_dyn_free(&mq->recvbuf); - free(mq); + curlx_free(mq); } static void mqtt_conn_dtor(void *key, size_t klen, void *entry) { (void)key; (void)klen; - free(entry); + curlx_free(entry); } static CURLcode mqtt_setup_conn(struct Curl_easy *data, @@ -163,12 +159,12 @@ static CURLcode mqtt_setup_conn(struct Curl_easy *data, struct mqtt_conn *mqtt; struct MQTT *mq; - mqtt = calloc(1, sizeof(*mqtt)); + mqtt = curlx_calloc(1, sizeof(*mqtt)); if(!mqtt || Curl_conn_meta_set(conn, CURL_META_MQTT_CONN, mqtt, mqtt_conn_dtor)) return CURLE_OUT_OF_MEMORY; - mq = calloc(1, sizeof(struct MQTT)); + mq = curlx_calloc(1, sizeof(struct MQTT)); if(!mq) return CURLE_OUT_OF_MEMORY; curlx_dyn_init(&mq->recvbuf, DYN_MQTT_RECV); @@ -350,7 +346,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) /* allocating packet */ if(packetlen > 0xFFFFFFF) return CURLE_WEIRD_SERVER_REPLY; - packet = calloc(1, packetlen); + packet = curlx_calloc(1, packetlen); if(!packet) return CURLE_OUT_OF_MEMORY; @@ -400,7 +396,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) end: if(packet) - free(packet); + curlx_free(packet); Curl_safefree(data->state.aptr.user); Curl_safefree(data->state.aptr.passwd); return result; @@ -524,7 +520,7 @@ static CURLcode mqtt_subscribe(struct Curl_easy *data) n = mqtt_encode_len((char *)encodedsize, packetlen); packetlen += n + 1; /* add one for the control packet type byte */ - packet = malloc(packetlen); + packet = curlx_malloc(packetlen); if(!packet) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -542,8 +538,8 @@ static CURLcode mqtt_subscribe(struct Curl_easy *data) result = mqtt_send(data, (const char *)packet, packetlen); fail: - free(topic); - free(packet); + curlx_free(topic); + curlx_free(packet); return result; } @@ -620,7 +616,7 @@ static CURLcode mqtt_publish(struct Curl_easy *data) } /* add the control byte and the encoded remaining length */ - pkt = malloc(remaininglength + 1 + encodelen); + pkt = curlx_malloc(remaininglength + 1 + encodelen); if(!pkt) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -639,8 +635,8 @@ static CURLcode mqtt_publish(struct Curl_easy *data) result = mqtt_send(data, (const char *)pkt, i); fail: - free(pkt); - free(topic); + curlx_free(pkt); + curlx_free(topic); return result; } diff --git a/lib/multi.c b/lib/multi.c index f7265a94a9..c5b78f53e4 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -54,10 +54,6 @@ #include "socks.h" #include "urlapi-int.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* initial multi->xfers table size for a full multi */ #define CURL_XFER_TABLE_SIZE 512 @@ -235,7 +231,7 @@ struct Curl_multi *Curl_multi_handle(uint32_t xfer_table_size, size_t dnssize, /* dns hash */ size_t sesssize) /* TLS session cache */ { - struct Curl_multi *multi = calloc(1, sizeof(struct Curl_multi)); + struct Curl_multi *multi = curlx_calloc(1, sizeof(struct Curl_multi)); if(!multi) return NULL; @@ -328,7 +324,7 @@ error: Curl_uint32_bset_destroy(&multi->msgsent); Curl_uint32_tbl_destroy(&multi->xfers); - free(multi); + curlx_free(multi); return NULL; } @@ -2022,7 +2018,7 @@ static CURLMcode state_performing(struct Curl_easy *data, data->state.errorbuf = FALSE; if(!newurl) /* typically for HTTP_1_1_REQUIRED error on first flight */ - newurl = strdup(data->state.url); + newurl = curlx_strdup(data->state.url); if(!newurl) { result = CURLE_OUT_OF_MEMORY; } @@ -2068,7 +2064,7 @@ static CURLMcode state_performing(struct Curl_easy *data, if(!retry) { /* if the URL is a follow-location and not just a retried request then figure out the URL here */ - free(newurl); + curlx_free(newurl); newurl = data->req.newurl; data->req.newurl = NULL; follow = FOLLOW_REDIR; @@ -2089,7 +2085,7 @@ static CURLMcode state_performing(struct Curl_easy *data, /* but first check to see if we got a location info even though we are not following redirects */ if(data->req.location) { - free(newurl); + curlx_free(newurl); newurl = data->req.location; data->req.location = NULL; result = multi_follow(data, handler, newurl, FOLLOW_FAKE); @@ -2109,7 +2105,7 @@ static CURLMcode state_performing(struct Curl_easy *data, *nowp = curlx_now(); mspeed_check(data, *nowp); } - free(newurl); + curlx_free(newurl); *resultp = result; return rc; } @@ -2237,7 +2233,7 @@ static CURLMcode state_do(struct Curl_easy *data, /* Have error handler disconnect conn if we cannot retry */ *stream_errorp = TRUE; } - free(newurl); + curlx_free(newurl); } else { /* failure detected */ @@ -2976,7 +2972,7 @@ CURLMcode curl_multi_cleanup(CURLM *m) Curl_uint32_bset_destroy(&multi->pending); Curl_uint32_bset_destroy(&multi->msgsent); Curl_uint32_tbl_destroy(&multi->xfers); - free(multi); + curlx_free(multi); return CURLM_OK; } @@ -3814,7 +3810,7 @@ CURL **curl_multi_get_handles(CURLM *m) struct Curl_multi *multi = m; void *entry; unsigned int count = Curl_uint32_tbl_count(&multi->xfers); - CURL **a = malloc(sizeof(struct Curl_easy *) * (count + 1)); + CURL **a = curlx_malloc(sizeof(struct Curl_easy *) * (count + 1)); if(a) { unsigned int i = 0, mid; @@ -3895,13 +3891,13 @@ 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 */ - free(data->multi->xfer_buf); + curlx_free(data->multi->xfer_buf); data->multi->xfer_buf = NULL; data->multi->xfer_buf_len = 0; } if(!data->multi->xfer_buf) { - data->multi->xfer_buf = malloc(curlx_uitouz(data->set.buffer_size)); + data->multi->xfer_buf = curlx_malloc(curlx_uitouz(data->set.buffer_size)); if(!data->multi->xfer_buf) { failf(data, "could not allocate xfer_buf of %u bytes", data->set.buffer_size); @@ -3948,14 +3944,14 @@ 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 */ - free(data->multi->xfer_ulbuf); + curlx_free(data->multi->xfer_ulbuf); data->multi->xfer_ulbuf = NULL; data->multi->xfer_ulbuf_len = 0; } if(!data->multi->xfer_ulbuf) { data->multi->xfer_ulbuf = - malloc(curlx_uitouz(data->set.upload_buffer_size)); + curlx_malloc(curlx_uitouz(data->set.upload_buffer_size)); if(!data->multi->xfer_ulbuf) { failf(data, "could not allocate xfer_ulbuf of %u bytes", data->set.upload_buffer_size); @@ -3996,13 +3992,13 @@ 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 */ - free(data->multi->xfer_sockbuf); + curlx_free(data->multi->xfer_sockbuf); data->multi->xfer_sockbuf = NULL; data->multi->xfer_sockbuf_len = 0; } if(!data->multi->xfer_sockbuf) { - data->multi->xfer_sockbuf = malloc(blen); + data->multi->xfer_sockbuf = curlx_malloc(blen); if(!data->multi->xfer_sockbuf) { failf(data, "could not allocate xfer_sockbuf of %zu bytes", blen); return CURLE_OUT_OF_MEMORY; diff --git a/lib/multi_ev.c b/lib/multi_ev.c index d5db331cf1..026cbd2996 100644 --- a/lib/multi_ev.c +++ b/lib/multi_ev.c @@ -41,10 +41,6 @@ #include "multihandle.h" #include "socks.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static void mev_in_callback(struct Curl_multi *multi, bool value) { @@ -85,7 +81,7 @@ static void mev_sh_entry_dtor(void *freethis) { struct mev_sh_entry *entry = (struct mev_sh_entry *)freethis; Curl_uint32_spbset_destroy(&entry->xfers); - free(entry); + curlx_free(entry); } /* look up a given socket in the socket hash, skip invalid sockets */ @@ -112,7 +108,7 @@ mev_sh_entry_add(struct Curl_hash *sh, curl_socket_t s) } /* not present, add it */ - check = calloc(1, sizeof(struct mev_sh_entry)); + check = curlx_calloc(1, sizeof(struct mev_sh_entry)); if(!check) return NULL; /* major failure */ @@ -446,7 +442,7 @@ static void mev_pollset_dtor(void *key, size_t klen, void *entry) (void)klen; if(ps) { Curl_pollset_cleanup(ps); - free(ps); + curlx_free(ps); } } diff --git a/lib/multi_ntfy.c b/lib/multi_ntfy.c index d7913bbbfc..43e4db9e82 100644 --- a/lib/multi_ntfy.c +++ b/lib/multi_ntfy.c @@ -32,11 +32,6 @@ #include "multiif.h" #include "multi_ntfy.h" -/* The last 3 #include files should be in this order */ -#include "curl_printf.h" -#include "curl_memory.h" -#include "memdebug.h" - struct mntfy_entry { uint32_t mid; @@ -54,12 +49,12 @@ struct mntfy_chunk { static struct mntfy_chunk *mnfty_chunk_create(void) { - return calloc(1, sizeof(struct mntfy_chunk)); + return curlx_calloc(1, sizeof(struct mntfy_chunk)); } static void mnfty_chunk_destroy(struct mntfy_chunk *chunk) { - free(chunk); + curlx_free(chunk); } static void mnfty_chunk_reset(struct mntfy_chunk *chunk) diff --git a/lib/netrc.c b/lib/netrc.c index 9c5c6c7f20..f8de408297 100644 --- a/lib/netrc.c +++ b/lib/netrc.c @@ -42,10 +42,6 @@ #include "curlx/fopen.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Get user and password from .netrc when given a machine name */ enum host_lookup_state { @@ -277,8 +273,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, our_login = !Curl_timestrcmp(login, tok); else { our_login = TRUE; - free(login); - login = strdup(tok); + curlx_free(login); + login = curlx_strdup(tok); if(!login) { retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */ goto out; @@ -288,8 +284,8 @@ static NETRCcode parsenetrc(struct store_netrc *store, keyword = NONE; } else if(keyword == PASSWORD) { - free(password); - password = strdup(tok); + curlx_free(password); + password = curlx_strdup(tok); if(!password) { retcode = NETRC_OUT_OF_MEMORY; /* allocation failed */ goto out; @@ -346,7 +342,7 @@ out: if(!retcode) { if(!password && our_login) { /* success without a password, set a blank one */ - password = strdup(""); + password = curlx_strdup(""); if(!password) retcode = NETRC_OUT_OF_MEMORY; /* out of memory */ } @@ -364,8 +360,8 @@ out: curlx_dyn_free(filebuf); store->loaded = FALSE; if(!specific_login) - free(login); - free(password); + curlx_free(login); + curlx_free(password); } return retcode; @@ -444,25 +440,25 @@ NETRCcode Curl_parsenetrc(struct store_netrc *store, const char *host, filealloc = curl_maprintf("%s%s.netrc", home, DIR_CHAR); if(!filealloc) { - free(homea); + curlx_free(homea); return NETRC_OUT_OF_MEMORY; } } retcode = parsenetrc(store, host, loginp, passwordp, filealloc); - free(filealloc); + curlx_free(filealloc); #ifdef _WIN32 if(retcode == NETRC_FILE_MISSING) { /* fallback to the old-style "_netrc" file */ filealloc = curl_maprintf("%s%s_netrc", home, DIR_CHAR); if(!filealloc) { - free(homea); + curlx_free(homea); return NETRC_OUT_OF_MEMORY; } retcode = parsenetrc(store, host, loginp, passwordp, filealloc); - free(filealloc); + curlx_free(filealloc); } #endif - free(homea); + curlx_free(homea); } else retcode = parsenetrc(store, host, loginp, passwordp, netrcfile); diff --git a/lib/openldap.c b/lib/openldap.c index 806ccb33cc..107f6da832 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -53,10 +53,6 @@ #include "curl_sasl.h" #include "strcase.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Uncommenting this will enable the built-in debug logging of the openldap * library. The debug log level can be set using the CURL_OPENLDAP_TRACE @@ -577,7 +573,7 @@ static void oldap_easy_dtor(void *key, size_t klen, void *entry) struct ldapreqinfo *lr = entry; (void)key; (void)klen; - free(lr); + curlx_free(lr); } static void oldap_conn_dtor(void *key, size_t klen, void *entry) @@ -589,7 +585,7 @@ static void oldap_conn_dtor(void *key, size_t klen, void *entry) ldap_unbind_ext(li->ld, NULL, NULL); li->ld = NULL; } - free(li); + curlx_free(li); } static CURLcode oldap_connect(struct Curl_easy *data, bool *done) @@ -606,7 +602,7 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done) (void)done; - li = calloc(1, sizeof(struct ldapconninfo)); + li = curlx_calloc(1, sizeof(struct ldapconninfo)); if(!li) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -697,7 +693,7 @@ static CURLcode oldap_connect(struct Curl_easy *data, bool *done) result = oldap_perform_bind(data, OLDAP_BIND); out: - free(hosturl); + curlx_free(hosturl); return result; } @@ -1023,7 +1019,7 @@ static CURLcode oldap_do(struct Curl_easy *data, bool *done) goto out; } - lr = calloc(1, sizeof(struct ldapreqinfo)); + lr = curlx_calloc(1, sizeof(struct ldapreqinfo)); if(!lr || Curl_meta_set(data, CURL_META_LDAP_EASY, lr, oldap_easy_dtor)) { ldap_abandon_ext(li->ld, msgid, NULL, NULL); @@ -1219,7 +1215,7 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf, if(!result) result = client_write(data, STRCONST(": "), val_b64, val_b64_sz, STRCONST("\n")); - free(val_b64); + curlx_free(val_b64); } else result = client_write(data, STRCONST(" "), diff --git a/lib/pingpong.c b/lib/pingpong.c index 297389043f..7ac321af72 100644 --- a/lib/pingpong.c +++ b/lib/pingpong.c @@ -37,10 +37,6 @@ #include "multiif.h" #include "vtls/vtls.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_PINGPONG /* Returns timeout in ms. 0 or negative number means the timeout has already diff --git a/lib/pop3.c b/lib/pop3.c index 503f4ecb2b..f10108229b 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -78,10 +78,6 @@ #include "curlx/warnless.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Authentication type flags */ #define POP3_TYPE_CLEARTEXT (1 << 0) #define POP3_TYPE_APOP (1 << 1) @@ -1523,7 +1519,7 @@ static void pop3_easy_dtor(void *key, size_t klen, void *entry) /* Cleanup our per-request based variables */ Curl_safefree(pop3->id); Curl_safefree(pop3->custom); - free(pop3); + curlx_free(pop3); } static void pop3_conn_dtor(void *key, size_t klen, void *entry) @@ -1534,19 +1530,19 @@ static void pop3_conn_dtor(void *key, size_t klen, void *entry) DEBUGASSERT(pop3c); Curl_pp_disconnect(&pop3c->pp); Curl_safefree(pop3c->apoptimestamp); - free(pop3c); + curlx_free(pop3c); } static CURLcode pop3_setup_connection(struct Curl_easy *data, struct connectdata *conn) { struct pop3_conn *pop3c; - struct POP3 *pop3 = calloc(1, sizeof(*pop3)); + struct POP3 *pop3 = curlx_calloc(1, sizeof(*pop3)); if(!pop3 || Curl_meta_set(data, CURL_META_POP3_EASY, pop3, pop3_easy_dtor)) return CURLE_OUT_OF_MEMORY; - pop3c = calloc(1, sizeof(*pop3c)); + pop3c = curlx_calloc(1, sizeof(*pop3c)); if(!pop3c || Curl_conn_meta_set(conn, CURL_META_POP3_CONN, pop3c, pop3_conn_dtor)) return CURLE_OUT_OF_MEMORY; diff --git a/lib/psl.c b/lib/psl.c index f645763d06..5bf96d09bd 100644 --- a/lib/psl.c +++ b/lib/psl.c @@ -31,10 +31,6 @@ #include "psl.h" #include "curl_share.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void Curl_psl_destroy(struct PslCache *pslcache) { if(pslcache->psl) { diff --git a/lib/rand.c b/lib/rand.c index 5eace02833..8c5a2cf71e 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -38,10 +38,6 @@ #include "rand.h" #include "escape.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA && \ diff --git a/lib/rename.c b/lib/rename.c index 911afca575..d3f80422e6 100644 --- a/lib/rename.c +++ b/lib/rename.c @@ -32,10 +32,6 @@ #include "curlx/multibyte.h" #include "curlx/timeval.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* return 0 on success, 1 on error */ int Curl_rename(const char *oldpath, const char *newpath) { diff --git a/lib/request.c b/lib/request.c index 324c4c48f9..581d7d1453 100644 --- a/lib/request.c +++ b/lib/request.c @@ -36,10 +36,6 @@ #include "url.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - void Curl_req_init(struct SingleRequest *req) { memset(req, 0, sizeof(*req)); diff --git a/lib/rtsp.c b/lib/rtsp.c index dd49ebc42b..5a46dc62c4 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -42,10 +42,6 @@ #include "strdup.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_RTSP_EASY "meta:proto:rtsp:easy" @@ -162,7 +158,7 @@ static void rtsp_easy_dtor(void *key, size_t klen, void *entry) struct RTSP *rtsp = entry; (void)key; (void)klen; - free(rtsp); + curlx_free(rtsp); } static void rtsp_conn_dtor(void *key, size_t klen, void *entry) @@ -171,7 +167,7 @@ static void rtsp_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; curlx_dyn_free(&rtspc->buf); - free(rtspc); + curlx_free(rtspc); } static CURLcode rtsp_setup_connection(struct Curl_easy *data, @@ -180,14 +176,14 @@ static CURLcode rtsp_setup_connection(struct Curl_easy *data, struct rtsp_conn *rtspc; struct RTSP *rtsp; - rtspc = calloc(1, sizeof(*rtspc)); + rtspc = curlx_calloc(1, sizeof(*rtspc)); if(!rtspc) return CURLE_OUT_OF_MEMORY; curlx_dyn_init(&rtspc->buf, MAX_RTP_BUFFERSIZE); if(Curl_conn_meta_set(conn, CURL_META_RTSP_CONN, rtspc, rtsp_conn_dtor)) return CURLE_OUT_OF_MEMORY; - rtsp = calloc(1, sizeof(struct RTSP)); + rtsp = curlx_calloc(1, sizeof(struct RTSP)); if(!rtsp || Curl_meta_set(data, CURL_META_RTSP_EASY, rtsp, rtsp_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -392,7 +388,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) to this origin */ if(!data->state.first_host) { - data->state.first_host = strdup(conn->host.name); + data->state.first_host = curlx_strdup(conn->host.name); if(!data->state.first_host) return CURLE_OUT_OF_MEMORY; @@ -481,7 +477,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) if(rtspreq == RTSPREQ_SETUP && !p_transport) { /* New Transport: setting? */ if(data->set.str[STRING_RTSP_TRANSPORT]) { - free(data->state.aptr.rtsp_transport); + curlx_free(data->state.aptr.rtsp_transport); data->state.aptr.rtsp_transport = curl_maprintf("Transport: %s\r\n", data->set.str[STRING_RTSP_TRANSPORT]); @@ -507,7 +503,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* Accept-Encoding header */ if(!Curl_checkheaders(data, STRCONST("Accept-Encoding")) && data->set.str[STRING_ENCODING]) { - free(data->state.aptr.accept_encoding); + curlx_free(data->state.aptr.accept_encoding); data->state.aptr.accept_encoding = curl_maprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]); @@ -563,7 +559,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) /* Check to see if there is a range set in the custom headers */ if(!Curl_checkheaders(data, STRCONST("Range")) && data->state.range) { - free(data->state.aptr.rangeline); + curlx_free(data->state.aptr.rangeline); data->state.aptr.rangeline = curl_maprintf("Range: %s\r\n", data->state.range); p_range = data->state.aptr.rangeline; diff --git a/lib/select.c b/lib/select.c index 041733973e..5692fc020d 100644 --- a/lib/select.c +++ b/lib/select.c @@ -46,10 +46,6 @@ #include "curlx/wait.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifndef HAVE_POLL /* * This is a wrapper around select() to aid in Windows compatibility. A @@ -364,7 +360,7 @@ void Curl_pollfds_cleanup(struct curl_pollfds *cpfds) { DEBUGASSERT(cpfds); if(cpfds->allocated_pfds) { - free(cpfds->pfds); + curlx_free(cpfds->pfds); } memset(cpfds, 0, sizeof(*cpfds)); } @@ -374,13 +370,13 @@ static CURLcode cpfds_increase(struct curl_pollfds *cpfds, unsigned int inc) struct pollfd *new_fds; unsigned int new_count = cpfds->count + inc; - new_fds = calloc(new_count, sizeof(struct pollfd)); + new_fds = curlx_calloc(new_count, sizeof(struct pollfd)); if(!new_fds) return CURLE_OUT_OF_MEMORY; memcpy(new_fds, cpfds->pfds, cpfds->count * sizeof(struct pollfd)); if(cpfds->allocated_pfds) - free(cpfds->pfds); + curlx_free(cpfds->pfds); cpfds->pfds = new_fds; cpfds->count = new_count; cpfds->allocated_pfds = TRUE; @@ -521,7 +517,7 @@ void Curl_pollset_init(struct easy_pollset *ps) struct easy_pollset *Curl_pollset_create(void) { - struct easy_pollset *ps = calloc(1, sizeof(*ps)); + struct easy_pollset *ps = curlx_calloc(1, sizeof(*ps)); if(ps) Curl_pollset_init(ps); return ps; @@ -533,11 +529,11 @@ void Curl_pollset_cleanup(struct easy_pollset *ps) DEBUGASSERT(ps->init == CURL_EASY_POLLSET_MAGIC); #endif if(ps->sockets != ps->def_sockets) { - free(ps->sockets); + curlx_free(ps->sockets); ps->sockets = ps->def_sockets; } if(ps->actions != ps->def_actions) { - free(ps->actions); + curlx_free(ps->actions); ps->actions = ps->def_actions; } ps->count = CURL_ARRAYSIZE(ps->def_sockets); @@ -614,21 +610,21 @@ CURLcode Curl_pollset_change(struct Curl_easy *data, ps->count, new_count); if(new_count <= ps->count) return CURLE_OUT_OF_MEMORY; - nsockets = calloc(new_count, sizeof(nsockets[0])); + nsockets = curlx_calloc(new_count, sizeof(nsockets[0])); if(!nsockets) return CURLE_OUT_OF_MEMORY; - nactions = calloc(new_count, sizeof(nactions[0])); + nactions = curlx_calloc(new_count, sizeof(nactions[0])); if(!nactions) { - free(nsockets); + curlx_free(nsockets); return CURLE_OUT_OF_MEMORY; } memcpy(nsockets, ps->sockets, ps->count * sizeof(ps->sockets[0])); memcpy(nactions, ps->actions, ps->count * sizeof(ps->actions[0])); if(ps->sockets != ps->def_sockets) - free(ps->sockets); + curlx_free(ps->sockets); ps->sockets = nsockets; if(ps->actions != ps->def_actions) - free(ps->actions); + curlx_free(ps->actions); ps->actions = nactions; ps->count = new_count; } @@ -668,7 +664,7 @@ int Curl_pollset_poll(struct Curl_easy *data, if(!ps->n) return curlx_wait_ms(timeout_ms); - pfds = calloc(ps->n, sizeof(*pfds)); + pfds = curlx_calloc(ps->n, sizeof(*pfds)); if(!pfds) return -1; @@ -689,7 +685,7 @@ int Curl_pollset_poll(struct Curl_easy *data, } result = Curl_poll(pfds, npfds, timeout_ms); - free(pfds); + curlx_free(pfds); return result; } diff --git a/lib/sendf.c b/lib/sendf.c index 6731cd874b..1d73291c92 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -55,10 +55,6 @@ #include "curlx/warnless.h" #include "ws.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode do_init_writer_stack(struct Curl_easy *data); @@ -100,7 +96,7 @@ static void cl_reset_writer(struct Curl_easy *data) while(writer) { data->req.writer_stack = writer->next; writer->cwt->do_close(data, writer); - free(writer); + curlx_free(writer); writer = data->req.writer_stack; } } @@ -112,7 +108,7 @@ static void cl_reset_reader(struct Curl_easy *data) while(reader) { data->req.reader_stack = reader->next; reader->crt->do_close(data, reader); - free(reader); + curlx_free(reader); reader = data->req.reader_stack; } } @@ -374,7 +370,7 @@ CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter, void *p; DEBUGASSERT(cwt->cwriter_size >= sizeof(struct Curl_cwriter)); - p = calloc(1, cwt->cwriter_size); + p = curlx_calloc(1, cwt->cwriter_size); if(!p) goto out; @@ -387,7 +383,7 @@ CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter, out: *pwriter = result ? NULL : writer; if(result) - free(writer); + curlx_free(writer); return result; } @@ -396,7 +392,7 @@ void Curl_cwriter_free(struct Curl_easy *data, { if(writer) { writer->cwt->do_close(data, writer); - free(writer); + curlx_free(writer); } } @@ -938,7 +934,7 @@ CURLcode Curl_creader_create(struct Curl_creader **preader, void *p; DEBUGASSERT(crt->creader_size >= sizeof(struct Curl_creader)); - p = calloc(1, crt->creader_size); + p = curlx_calloc(1, crt->creader_size); if(!p) goto out; @@ -951,7 +947,7 @@ CURLcode Curl_creader_create(struct Curl_creader **preader, out: *preader = result ? NULL : reader; if(result) - free(reader); + curlx_free(reader); return result; } @@ -959,7 +955,7 @@ void Curl_creader_free(struct Curl_easy *data, struct Curl_creader *reader) { if(reader) { reader->crt->do_close(data, reader); - free(reader); + curlx_free(reader); } } diff --git a/lib/setopt.c b/lib/setopt.c index 36f447cdc5..b4ca361ce3 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -55,10 +55,6 @@ #include "strdup.h" #include "escape.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - static CURLcode setopt_set_timeout_sec(timediff_t *ptimeout_ms, long secs) { if(secs < 0) @@ -98,7 +94,7 @@ CURLcode Curl_setstropt(char **charp, const char *s) if(strlen(s) > CURL_MAX_INPUT_LENGTH) return CURLE_BAD_FUNCTION_ARGUMENT; - *charp = strdup(s); + *charp = curlx_strdup(s); if(!*charp) return CURLE_OUT_OF_MEMORY; } @@ -119,8 +115,8 @@ CURLcode Curl_setblobopt(struct curl_blob **blobp, if(blob->len > CURL_MAX_INPUT_LENGTH) return CURLE_BAD_FUNCTION_ARGUMENT; nblob = (struct curl_blob *) - malloc(sizeof(struct curl_blob) + - ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0)); + curlx_malloc(sizeof(struct curl_blob) + + ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0)); if(!nblob) return CURLE_OUT_OF_MEMORY; *nblob = *blob; @@ -158,10 +154,10 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp) return result; } - free(*userp); + curlx_free(*userp); *userp = user; - free(*passwdp); + curlx_free(*passwdp); *passwdp = passwd; return CURLE_OK; @@ -185,13 +181,13 @@ static CURLcode setstropt_interface(char *option, char **devp, if(result) return result; } - free(*devp); + curlx_free(*devp); *devp = dev; - free(*ifacep); + curlx_free(*ifacep); *ifacep = iface; - free(*hostp); + curlx_free(*hostp); *hostp = host; return CURLE_OK; @@ -1706,7 +1702,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, if(!p) return CURLE_OUT_OF_MEMORY; else { - free(s->str[STRING_COPYPOSTFIELDS]); + curlx_free(s->str[STRING_COPYPOSTFIELDS]); s->str[STRING_COPYPOSTFIELDS] = p; } } @@ -2040,8 +2036,8 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, result = Curl_urldecode(p, 0, &s->str[STRING_PROXYPASSWORD], NULL, REJECT_ZERO); } - free(u); - free(p); + curlx_free(u); + curlx_free(p); } break; case CURLOPT_PROXYUSERNAME: diff --git a/lib/sha256.c b/lib/sha256.c index 3e3205e36b..977ad3edc4 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -59,10 +59,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* Please keep the SSL backend-specific #if branches in this order: * * 1. USE_OPENSSL diff --git a/lib/slist.c b/lib/slist.c index 88fdd8a2ba..469ee0ef3b 100644 --- a/lib/slist.c +++ b/lib/slist.c @@ -28,10 +28,6 @@ #include "slist.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - /* returns last node in linked list */ static struct curl_slist *slist_get_last(struct curl_slist *list) { @@ -66,7 +62,7 @@ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, DEBUGASSERT(data); - new_item = malloc(sizeof(struct curl_slist)); + new_item = curlx_malloc(sizeof(struct curl_slist)); if(!new_item) return NULL; @@ -92,14 +88,14 @@ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list, struct curl_slist *curl_slist_append(struct curl_slist *list, const char *data) { - char *dupdata = strdup(data); + char *dupdata = curlx_strdup(data); if(!dupdata) return NULL; list = Curl_slist_append_nodup(list, dupdata); if(!list) - free(dupdata); + curlx_free(dupdata); return list; } @@ -141,7 +137,7 @@ void curl_slist_free_all(struct curl_slist *list) do { next = item->next; Curl_safefree(item->data); - free(item); + curlx_free(item); item = next; } while(next); } diff --git a/lib/smb.c b/lib/smb.c index e5fca3ec0b..338464961b 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -42,10 +42,6 @@ #include "escape.h" #include "curl_endian.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_SMB_EASY "meta:proto:smb:easy" @@ -451,7 +447,7 @@ static void smb_easy_dtor(void *key, size_t klen, void *entry) /* `req->path` points to somewhere in `struct smb_conn` which is * kept at the connection meta. If the connection is destroyed first, * req->path points to free'd memory. */ - free(req); + curlx_free(req); } static void smb_conn_dtor(void *key, size_t klen, void *entry) @@ -463,7 +459,7 @@ static void smb_conn_dtor(void *key, size_t klen, void *entry) Curl_safefree(smbc->domain); Curl_safefree(smbc->recv_buf); Curl_safefree(smbc->send_buf); - free(smbc); + curlx_free(smbc); } /* this should setup things in the connection, not in the easy @@ -475,13 +471,13 @@ static CURLcode smb_setup_connection(struct Curl_easy *data, struct smb_request *req; /* Initialize the connection state */ - smbc = calloc(1, sizeof(*smbc)); + smbc = curlx_calloc(1, sizeof(*smbc)); if(!smbc || Curl_conn_meta_set(conn, CURL_META_SMB_CONN, smbc, smb_conn_dtor)) return CURLE_OUT_OF_MEMORY; /* Initialize the request state */ - req = calloc(1, sizeof(*req)); + req = curlx_calloc(1, sizeof(*req)); if(!req || Curl_meta_set(data, CURL_META_SMB_EASY, req, smb_easy_dtor)) return CURLE_OUT_OF_MEMORY; @@ -506,10 +502,10 @@ static CURLcode smb_connect(struct Curl_easy *data, bool *done) /* Initialize the connection state */ smbc->state = SMB_CONNECTING; - smbc->recv_buf = malloc(MAX_MESSAGE_SIZE); + smbc->recv_buf = curlx_malloc(MAX_MESSAGE_SIZE); if(!smbc->recv_buf) return CURLE_OUT_OF_MEMORY; - smbc->send_buf = malloc(MAX_MESSAGE_SIZE); + smbc->send_buf = curlx_malloc(MAX_MESSAGE_SIZE); if(!smbc->send_buf) return CURLE_OUT_OF_MEMORY; @@ -520,14 +516,14 @@ static CURLcode smb_connect(struct Curl_easy *data, bool *done) if(slash) { smbc->user = slash + 1; - smbc->domain = strdup(conn->user); + smbc->domain = curlx_strdup(conn->user); if(!smbc->domain) return CURLE_OUT_OF_MEMORY; smbc->domain[slash - conn->user] = 0; } else { smbc->user = conn->user; - smbc->domain = strdup(conn->host.name); + smbc->domain = curlx_strdup(conn->host.name); if(!smbc->domain) return CURLE_OUT_OF_MEMORY; } @@ -1246,8 +1242,9 @@ static CURLcode smb_parse_url_path(struct Curl_easy *data, return result; /* Parse the path for the share */ - smbc->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path); - free(path); + smbc->share = curlx_strdup((*path == '/' || *path == '\\') + ? path + 1 : path); + curlx_free(path); if(!smbc->share) return CURLE_OUT_OF_MEMORY; diff --git a/lib/smtp.c b/lib/smtp.c index eca27f1465..55a15b36c0 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -81,10 +81,6 @@ #include "idn.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* meta key for storing protocol meta at easy handle */ #define CURL_META_SMTP_EASY "meta:proto:smtp:easy" /* meta key for storing protocol meta at connection */ @@ -646,7 +642,7 @@ static CURLcode smtp_perform_command(struct Curl_easy *data, utf8 ? " SMTPUTF8" : ""); Curl_free_idnconverted_hostname(&host); - free(address); + curlx_free(address); } else { /* Establish whether we should report that we support SMTPUTF8 for EXPN @@ -722,11 +718,11 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, worry about that and reply with a 501 error */ from = curl_maprintf("<%s>%s", address, suffix); - free(address); + curlx_free(address); } else /* Null reverse-path, RFC-5321, sect. 3.6.3 */ - from = strdup("<>"); + from = curlx_strdup("<>"); if(!from) { result = CURLE_OUT_OF_MEMORY; @@ -763,11 +759,11 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, /* An invalid mailbox was provided but we will simply let the server worry about it */ auth = curl_maprintf("<%s>%s", address, suffix); - free(address); + curlx_free(address); } else /* Empty AUTH, RFC-2554, sect. 5 */ - auth = strdup("<>"); + auth = curlx_strdup("<>"); if(!auth) { result = CURLE_OUT_OF_MEMORY; @@ -848,9 +844,9 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data, : ""); /* included in our envelope */ out: - free(from); - free(auth); - free(size); + curlx_free(from); + curlx_free(auth); + curlx_free(size); if(!result) smtp_state(data, smtpc, SMTP_MAIL); @@ -892,7 +888,7 @@ static CURLcode smtp_perform_rcpt_to(struct Curl_easy *data, address, suffix); Curl_free_idnconverted_hostname(&host); - free(address); + curlx_free(address); if(!result) smtp_state(data, smtpc, SMTP_RCPT); @@ -1716,7 +1712,7 @@ static void smtp_easy_dtor(void *key, size_t klen, void *entry) struct SMTP *smtp = entry; (void)key; (void)klen; - free(smtp); + curlx_free(smtp); } static void smtp_conn_dtor(void *key, size_t klen, void *entry) @@ -1726,7 +1722,7 @@ static void smtp_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_pp_disconnect(&smtpc->pp); Curl_safefree(smtpc->domain); - free(smtpc); + curlx_free(smtpc); } static CURLcode smtp_setup_connection(struct Curl_easy *data, @@ -1736,14 +1732,14 @@ static CURLcode smtp_setup_connection(struct Curl_easy *data, struct SMTP *smtp; CURLcode result = CURLE_OK; - smtpc = calloc(1, sizeof(*smtpc)); + smtpc = curlx_calloc(1, sizeof(*smtpc)); if(!smtpc || Curl_conn_meta_set(conn, CURL_META_SMTP_CONN, smtpc, smtp_conn_dtor)) { result = CURLE_OUT_OF_MEMORY; goto out; } - smtp = calloc(1, sizeof(*smtp)); + smtp = curlx_calloc(1, sizeof(*smtp)); if(!smtp || Curl_meta_set(data, CURL_META_SMTP_EASY, smtp, smtp_easy_dtor)) result = CURLE_OUT_OF_MEMORY; @@ -1877,7 +1873,7 @@ static CURLcode smtp_parse_address(const char *fqma, char **address, /* Duplicate the fully qualified email address so we can manipulate it, ensuring it does not contain the delimiters if specified */ - char *dup = strdup(fqma[0] == '<' ? fqma + 1 : fqma); + char *dup = curlx_strdup(fqma[0] == '<' ? fqma + 1 : fqma); if(!dup) return CURLE_OUT_OF_MEMORY; diff --git a/lib/socketpair.c b/lib/socketpair.c index 08753c8a8c..0b61112044 100644 --- a/lib/socketpair.c +++ b/lib/socketpair.c @@ -134,10 +134,6 @@ int Curl_socketpair(int domain, int type, int protocol, #include "curlx/timeval.h" /* needed before select.h */ #include "select.h" /* for Curl_poll */ -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - int Curl_socketpair(int domain, int type, int protocol, curl_socket_t socks[2], bool nonblocking) { diff --git a/lib/socks.c b/lib/socks.c index 3434030c83..7160dd1506 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -45,10 +45,6 @@ #include "curlx/inet_pton.h" #include "url.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS) #define DEBUG_AND_VERBOSE #endif @@ -1215,7 +1211,7 @@ static void socks_proxy_cf_free(struct Curl_cfilter *cf) struct socks_state *sxstate = cf->ctx; if(sxstate) { Curl_bufq_free(&sxstate->iobuf); - free(sxstate); + curlx_free(sxstate); cf->ctx = NULL; } } @@ -1247,7 +1243,7 @@ static CURLcode socks_proxy_cf_connect(struct Curl_cfilter *cf, return result; if(!sx) { - cf->ctx = sx = calloc(1, sizeof(*sx)); + cf->ctx = sx = curlx_calloc(1, sizeof(*sx)); if(!sx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/socks_gssapi.c b/lib/socks_gssapi.c index 61c88be605..6f8a90139d 100644 --- a/lib/socks_gssapi.c +++ b/lib/socks_gssapi.c @@ -37,10 +37,6 @@ #include "curlx/warnless.h" #include "strdup.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if defined(__GNUC__) && defined(__APPLE__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -151,8 +147,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, (gss_OID) GSS_C_NULL_OID, &server); } else { - service.value = malloc(serviceptr_length + - strlen(conn->socks_proxy.host.name) + 2); + service.value = curlx_malloc(serviceptr_length + + strlen(conn->socks_proxy.host.name) + 2); if(!service.value) return CURLE_OUT_OF_MEMORY; service.length = serviceptr_length + @@ -277,7 +273,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); gss_recv_token.length = us_length; - gss_recv_token.value = malloc(gss_recv_token.length); + gss_recv_token.value = curlx_malloc(gss_recv_token.length); if(!gss_recv_token.value) { failf(data, "Could not allocate memory for GSS-API authentication " @@ -464,7 +460,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); gss_recv_token.length = us_length; - gss_recv_token.value = malloc(gss_recv_token.length); + gss_recv_token.value = curlx_malloc(gss_recv_token.length); if(!gss_recv_token.value) { Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL); return CURLE_OUT_OF_MEMORY; diff --git a/lib/socks_sspi.c b/lib/socks_sspi.c index 14025371ce..92592c5ce0 100644 --- a/lib/socks_sspi.c +++ b/lib/socks_sspi.c @@ -38,10 +38,6 @@ #include "curlx/multibyte.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* * Helper sspi error functions. */ @@ -101,7 +97,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, /* prepare service name */ if(strchr(service, '/')) - service_name = strdup(service); + service_name = curlx_strdup(service); else service_name = curl_maprintf("%s/%s", service, conn->socks_proxy.host.name); @@ -267,7 +263,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); sspi_recv_token.cbBuffer = us_length; - sspi_recv_token.pvBuffer = malloc(us_length); + sspi_recv_token.pvBuffer = curlx_malloc(us_length); if(!sspi_recv_token.pvBuffer) { result = CURLE_OUT_OF_MEMORY; @@ -371,7 +367,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, sspi_w_token[0].cbBuffer = sspi_sizes.cbSecurityTrailer; sspi_w_token[0].BufferType = SECBUFFER_TOKEN; - sspi_w_token[0].pvBuffer = malloc(sspi_sizes.cbSecurityTrailer); + sspi_w_token[0].pvBuffer = curlx_malloc(sspi_sizes.cbSecurityTrailer); if(!sspi_w_token[0].pvBuffer) { result = CURLE_OUT_OF_MEMORY; @@ -379,7 +375,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } sspi_w_token[1].cbBuffer = 1; - sspi_w_token[1].pvBuffer = malloc(1); + sspi_w_token[1].pvBuffer = curlx_malloc(1); if(!sspi_w_token[1].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -388,7 +384,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, memcpy(sspi_w_token[1].pvBuffer, &gss_enc, 1); sspi_w_token[2].BufferType = SECBUFFER_PADDING; sspi_w_token[2].cbBuffer = sspi_sizes.cbBlockSize; - sspi_w_token[2].pvBuffer = malloc(sspi_sizes.cbBlockSize); + sspi_w_token[2].pvBuffer = curlx_malloc(sspi_sizes.cbBlockSize); if(!sspi_w_token[2].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -409,7 +405,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, result = CURLE_COULDNT_CONNECT; goto error; } - etbuf = malloc(etbuf_size); + etbuf = curlx_malloc(etbuf_size); if(!etbuf) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -486,7 +482,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, us_length = ntohs(us_length); sspi_w_token[0].cbBuffer = us_length; - sspi_w_token[0].pvBuffer = malloc(us_length); + sspi_w_token[0].pvBuffer = curlx_malloc(us_length); if(!sspi_w_token[0].pvBuffer) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -514,7 +510,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, /* since sspi_w_token[1].pvBuffer is allocated by the SSPI in this case, it must be freed in this block using FreeContextBuffer() instead of - potentially in error cleanup using free(). */ + potentially in error cleanup using curlx_free(). */ if(check_sspi_err(data, status, "DecryptMessage")) { failf(data, "Failed to query security context attributes."); @@ -577,18 +573,18 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, return CURLE_OK; error: (void)curlx_nonblock(sock, TRUE); - free(service_name); + curlx_free(service_name); Curl_pSecFn->DeleteSecurityContext(&sspi_context); Curl_pSecFn->FreeCredentialsHandle(&cred_handle); - free(sspi_recv_token.pvBuffer); + curlx_free(sspi_recv_token.pvBuffer); if(sspi_send_token.pvBuffer) Curl_pSecFn->FreeContextBuffer(sspi_send_token.pvBuffer); if(names.sUserName) Curl_pSecFn->FreeContextBuffer(names.sUserName); - free(sspi_w_token[0].pvBuffer); - free(sspi_w_token[1].pvBuffer); - free(sspi_w_token[2].pvBuffer); - free(etbuf); + curlx_free(sspi_w_token[0].pvBuffer); + curlx_free(sspi_w_token[1].pvBuffer); + curlx_free(sspi_w_token[2].pvBuffer); + curlx_free(etbuf); return result; } #endif diff --git a/lib/strdup.c b/lib/strdup.c index 3339e909ee..375f0f5044 100644 --- a/lib/strdup.c +++ b/lib/strdup.c @@ -31,10 +31,6 @@ #endif #include "strdup.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" #ifndef HAVE_STRDUP char *Curl_strdup(const char *str) @@ -47,7 +43,7 @@ char *Curl_strdup(const char *str) len = strlen(str) + 1; - newstr = malloc(len); + newstr = curlx_malloc(len); if(!newstr) return (char *)NULL; @@ -90,7 +86,7 @@ wchar_t *Curl_wcsdup(const wchar_t *src) ***************************************************************************/ void *Curl_memdup(const void *src, size_t length) { - void *buffer = malloc(length); + void *buffer = curlx_malloc(length); if(!buffer) return NULL; /* fail */ @@ -111,7 +107,7 @@ void *Curl_memdup(const void *src, size_t length) ***************************************************************************/ void *Curl_memdup0(const char *src, size_t length) { - char *buf = (length < SIZE_MAX) ? malloc(length + 1) : NULL; + char *buf = (length < SIZE_MAX) ? curlx_malloc(length + 1) : NULL; if(!buf) return NULL; if(length) { @@ -126,7 +122,7 @@ void *Curl_memdup0(const char *src, size_t length) * * Curl_saferealloc(ptr, size) * - * Does a normal realloc(), but will free the data pointer if the realloc + * 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. * * This convenience function is provided and used to help us avoid a common @@ -138,9 +134,9 @@ void *Curl_memdup0(const char *src, size_t length) ***************************************************************************/ void *Curl_saferealloc(void *ptr, size_t size) { - void *datap = realloc(ptr, size); + void *datap = curlx_realloc(ptr, size); if(size && !datap) /* only free 'ptr' if size was non-zero */ - free(ptr); + curlx_free(ptr); return datap; } diff --git a/lib/strerror.c b/lib/strerror.c index afe69756bc..4b957bef23 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -34,10 +34,6 @@ #include "curlx/winapi.h" #include "strerror.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - const char * curl_easy_strerror(CURLcode error) { diff --git a/lib/system_win32.c b/lib/system_win32.c index bdbed66162..f8a6cbfccc 100644 --- a/lib/system_win32.c +++ b/lib/system_win32.c @@ -32,10 +32,6 @@ #include "curl_sspi.h" #include "curlx/warnless.h" -/* The last #include files should be: */ -#include "curl_memory.h" -#include "memdebug.h" - #ifndef HAVE_IF_NAMETOINDEX /* Handle of iphlpapp.dll */ static HMODULE s_hIpHlpApiDll = NULL; @@ -218,7 +214,8 @@ static HMODULE curl_load_library(LPCTSTR filename) /* Allocate space for the full DLL path (Room for the null-terminator is included in systemdirlen) */ size_t filenamelen = _tcslen(filename); - TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen)); + TCHAR *path = curlx_malloc(sizeof(TCHAR) * + (systemdirlen + 1 + filenamelen)); if(path && GetSystemDirectory(path, systemdirlen)) { /* Calculate the full DLL path */ _tcscpy(path + _tcslen(path), TEXT("\\")); @@ -230,7 +227,7 @@ static HMODULE curl_load_library(LPCTSTR filename) pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : LoadLibrary(path); } - free(path); + curlx_free(path); } } return hModule; diff --git a/lib/telnet.c b/lib/telnet.c index d0ca5a66ce..5319130b90 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -60,10 +60,6 @@ #include "curlx/warnless.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #define SUBBUFSIZE 512 #define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer @@ -211,7 +207,7 @@ static void telnet_easy_dtor(void *key, size_t klen, void *entry) (void)klen; curl_slist_free_all(tn->telnet_vars); curlx_dyn_free(&tn->out); - free(tn); + curlx_free(tn); } static @@ -219,7 +215,7 @@ CURLcode init_telnet(struct Curl_easy *data) { struct TELNET *tn; - tn = calloc(1, sizeof(struct TELNET)); + tn = curlx_calloc(1, sizeof(struct TELNET)); if(!tn) return CURLE_OUT_OF_MEMORY; diff --git a/lib/tftp.c b/lib/tftp.c index ce9d200f05..5311a4c683 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -64,10 +64,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /* RFC2348 allows the block size to be negotiated */ #define TFTP_BLKSIZE_DEFAULT 512 #define TFTP_OPTION_BLKSIZE "blksize" @@ -470,7 +466,7 @@ static CURLcode tftp_send_first(struct tftp_conn *state, if(strlen(filename) > (state->blksize - strlen(mode) - 4)) { failf(data, "TFTP filename too long"); - free(filename); + curlx_free(filename); return CURLE_TFTP_ILLEGAL; /* too long filename field */ } @@ -478,7 +474,7 @@ static CURLcode tftp_send_first(struct tftp_conn *state, state->blksize, "%s%c%s%c", filename, '\0', mode, '\0'); sbytes = 4 + strlen(filename) + strlen(mode); - free(filename); + curlx_free(filename); /* optional addition of TFTP options */ if(!data->set.tftp_no_options) { @@ -946,7 +942,7 @@ static void tftp_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_safefree(state->rpacket.data); Curl_safefree(state->spacket.data); - free(state); + curlx_free(state); } /********************************************************** @@ -967,7 +963,7 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) blksize = TFTP_BLKSIZE_DEFAULT; - state = calloc(1, sizeof(*state)); + state = curlx_calloc(1, sizeof(*state)); if(!state || Curl_conn_meta_set(conn, CURL_META_TFTP_CONN, state, tftp_conn_dtor)) return CURLE_OUT_OF_MEMORY; @@ -983,14 +979,14 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) need_blksize = TFTP_BLKSIZE_DEFAULT; if(!state->rpacket.data) { - state->rpacket.data = calloc(1, need_blksize + 2 + 2); + state->rpacket.data = curlx_calloc(1, need_blksize + 2 + 2); if(!state->rpacket.data) return CURLE_OUT_OF_MEMORY; } if(!state->spacket.data) { - state->spacket.data = calloc(1, need_blksize + 2 + 2); + state->spacket.data = curlx_calloc(1, need_blksize + 2 + 2); if(!state->spacket.data) return CURLE_OUT_OF_MEMORY; diff --git a/lib/transfer.c b/lib/transfer.c index f0ce3c5012..d8a0d6c0ba 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -81,10 +81,6 @@ #include "headers.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \ !defined(CURL_DISABLE_IMAP) /* @@ -479,7 +475,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) is allowed to be changed by the user between transfers */ if(data->set.uh) { CURLUcode uc; - free(data->set.str[STRING_SET_URL]); + curlx_free(data->set.str[STRING_SET_URL]); uc = curl_url_get(data->set.uh, CURLUPART_URL, &data->set.str[STRING_SET_URL], 0); if(uc) { @@ -574,7 +570,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) if(data->state.wildcardmatch) { struct WildcardData *wc; if(!data->wildcard) { - data->wildcard = calloc(1, sizeof(struct WildcardData)); + data->wildcard = curlx_calloc(1, sizeof(struct WildcardData)); if(!data->wildcard) return CURLE_OUT_OF_MEMORY; } @@ -597,7 +593,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) * protocol. */ if(!result && data->set.str[STRING_USERAGENT]) { - free(data->state.aptr.uagent); + curlx_free(data->state.aptr.uagent); data->state.aptr.uagent = curl_maprintf("User-Agent: %s\r\n", data->set.str[STRING_USERAGENT]); if(!data->state.aptr.uagent) @@ -629,7 +625,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data) /* Returns CURLE_OK *and* sets '*url' if a request retry is wanted. - NOTE: that the *url is malloc()ed. */ + NOTE: that the *url is curlx_malloc()ed. */ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) { struct connectdata *conn = data->conn; @@ -680,7 +676,7 @@ CURLcode Curl_retry_request(struct Curl_easy *data, char **url) } infof(data, "Connection died, retrying a fresh connect (retry count: %d)", data->state.retrycount); - *url = strdup(data->state.url); + *url = curlx_strdup(data->state.url); if(!*url) return CURLE_OUT_OF_MEMORY; diff --git a/lib/uint-bset.c b/lib/uint-bset.c index 82440c5637..dcad94e42a 100644 --- a/lib/uint-bset.c +++ b/lib/uint-bset.c @@ -25,10 +25,6 @@ #include "curl_setup.h" #include "uint-bset.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define CURL_UINT32_BSET_MAGIC 0x62757473 #endif @@ -49,14 +45,14 @@ CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax) DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); if(nslots != bset->nslots) { - uint64_t *slots = calloc(nslots, sizeof(uint64_t)); + uint64_t *slots = curlx_calloc(nslots, sizeof(uint64_t)); if(!slots) return CURLE_OUT_OF_MEMORY; if(bset->slots) { memcpy(slots, bset->slots, (CURLMIN(nslots, bset->nslots) * sizeof(uint64_t))); - free(bset->slots); + curlx_free(bset->slots); } bset->slots = slots; bset->nslots = nslots; @@ -69,7 +65,7 @@ CURLcode Curl_uint32_bset_resize(struct uint32_bset *bset, uint32_t nmax) void Curl_uint32_bset_destroy(struct uint32_bset *bset) { DEBUGASSERT(bset->init == CURL_UINT32_BSET_MAGIC); - free(bset->slots); + curlx_free(bset->slots); memset(bset, 0, sizeof(*bset)); } diff --git a/lib/uint-hash.c b/lib/uint-hash.c index 4677c6ac91..166a9ab99b 100644 --- a/lib/uint-hash.c +++ b/lib/uint-hash.c @@ -27,10 +27,6 @@ #include #include "uint-hash.h" -#include "curl_memory.h" - -/* The last #include file should be: */ -#include "memdebug.h" /* random patterns for API verification */ #ifdef DEBUGBUILD @@ -70,7 +66,7 @@ static struct uint_hash_entry *uint32_hash_mk_entry(uint32_t id, void *value) struct uint_hash_entry *e; /* allocate the struct for the hash entry */ - e = malloc(sizeof(*e)); + e = curlx_malloc(sizeof(*e)); if(e) { e->id = id; e->next = NULL; @@ -95,7 +91,7 @@ static void uint32_hash_entry_destroy(struct uint_hash *h, struct uint_hash_entry *e) { uint32_hash_entry_clear(h, e); - free(e); + curlx_free(e); } static void uint32_hash_entry_unlink(struct uint_hash *h, @@ -126,7 +122,7 @@ bool Curl_uint32_hash_set(struct uint_hash *h, uint32_t id, void *value) DEBUGASSERT(h->slots); DEBUGASSERT(h->init == CURL_UINT32_HASHINIT); if(!h->table) { - h->table = calloc(h->slots, sizeof(*he)); + h->table = curlx_calloc(h->slots, sizeof(*he)); if(!h->table) return FALSE; /* OOM */ } diff --git a/lib/uint-spbset.c b/lib/uint-spbset.c index f250bcb1b4..c726bfb900 100644 --- a/lib/uint-spbset.c +++ b/lib/uint-spbset.c @@ -26,10 +26,6 @@ #include "uint-bset.h" #include "uint-spbset.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define CURL_UINT32_SPBSET_MAGIC 0x70737362 #endif @@ -85,7 +81,7 @@ UNITTEST void Curl_uint32_spbset_clear(struct uint32_spbset *bset) for(chunk = bset->head.next; chunk; chunk = next) { next = chunk->next; - free(chunk); + curlx_free(chunk); } memset(&bset->head, 0, sizeof(bset->head)); } @@ -116,7 +112,7 @@ uint32_spbset_get_chunk(struct uint32_spbset *bset, uint32_t i, bool grow) return NULL; /* need a new one */ - chunk = calloc(1, sizeof(*chunk)); + chunk = curlx_calloc(1, sizeof(*chunk)); if(!chunk) return NULL; diff --git a/lib/uint-table.c b/lib/uint-table.c index 5516ab634b..05b53766f3 100644 --- a/lib/uint-table.c +++ b/lib/uint-table.c @@ -25,10 +25,6 @@ #include "curl_setup.h" #include "uint-table.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef DEBUGBUILD #define CURL_UINT32_TBL_MAGIC 0x62757473 #endif @@ -73,14 +69,14 @@ CURLcode Curl_uint32_tbl_resize(struct uint32_tbl *tbl, uint32_t nrows) if(!nrows) return CURLE_BAD_FUNCTION_ARGUMENT; if(nrows != tbl->nrows) { - void **rows = calloc(nrows, sizeof(void *)); + void **rows = curlx_calloc(nrows, sizeof(void *)); if(!rows) return CURLE_OUT_OF_MEMORY; if(tbl->rows) { memcpy(rows, tbl->rows, (CURLMIN(nrows, tbl->nrows) * sizeof(void *))); if(nrows < tbl->nrows) uint32_tbl_clear_rows(tbl, nrows, tbl->nrows); - free(tbl->rows); + curlx_free(tbl->rows); } tbl->rows = rows; tbl->nrows = nrows; @@ -93,7 +89,7 @@ void Curl_uint32_tbl_destroy(struct uint32_tbl *tbl) { DEBUGASSERT(tbl->init == CURL_UINT32_TBL_MAGIC); Curl_uint32_tbl_clear(tbl); - free(tbl->rows); + curlx_free(tbl->rows); memset(tbl, 0, sizeof(*tbl)); } diff --git a/lib/url.c b/lib/url.c index e7f39d5471..b4c33236cd 100644 --- a/lib/url.c +++ b/lib/url.c @@ -126,10 +126,6 @@ #include "curlx/strerr.h" #include "curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef USE_NGHTTP2 static void data_priority_cleanup(struct Curl_easy *data); #else @@ -257,7 +253,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_expire_clear(data); /* shut off any timers left */ if(data->state.rangestringalloc) - free(data->state.range); + curlx_free(data->state.range); /* release any resolve information this transfer kept */ Curl_async_destroy(data); @@ -346,7 +342,7 @@ CURLcode Curl_close(struct Curl_easy **datap) Curl_freeset(data); Curl_headers_cleanup(data); Curl_netrc_cleanup(&data->state.netrc); - free(data); + curlx_free(data); return CURLE_OK; } @@ -500,7 +496,7 @@ CURLcode Curl_open(struct Curl_easy **curl) struct Curl_easy *data; /* simple start-up: alloc the struct, init it with zeroes and return */ - data = calloc(1, sizeof(struct Curl_easy)); + data = curlx_calloc(1, sizeof(struct Curl_easy)); if(!data) { /* this is a serious error */ DEBUGF(curl_mfprintf(stderr, "Error: calloc of Curl_easy failed\n")); @@ -578,7 +574,7 @@ void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn) Curl_uint32_spbset_destroy(&conn->xfers_attached); Curl_hash_destroy(&conn->meta_hash); - free(conn); /* free all the connection oriented data */ + curlx_free(conn); /* free all the connection oriented data */ } /* @@ -1351,7 +1347,7 @@ ConnectionExists(struct Curl_easy *data, */ static struct connectdata *allocate_conn(struct Curl_easy *data) { - struct connectdata *conn = calloc(1, sizeof(struct connectdata)); + struct connectdata *conn = curlx_calloc(1, sizeof(struct connectdata)); if(!conn) return NULL; @@ -1406,7 +1402,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) /* Store the local bind parameters that will be used for this connection */ if(data->set.str[STRING_DEVICE]) { - conn->localdev = strdup(data->set.str[STRING_DEVICE]); + conn->localdev = curlx_strdup(data->set.str[STRING_DEVICE]); if(!conn->localdev) goto error; } @@ -1427,8 +1423,8 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) return conn; error: - free(conn->localdev); - free(conn); + curlx_free(conn->localdev); + curlx_free(conn); return NULL; } @@ -1747,7 +1743,7 @@ static void zonefrom_url(CURLU *uh, struct Curl_easy *data, } #endif /* HAVE_IF_NAMETOINDEX || _WIN32 */ - free(zoneid); + curlx_free(zoneid); } } #else @@ -1787,7 +1783,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, if(!url) return CURLE_OUT_OF_MEMORY; if(data->state.url_alloc) - free(data->state.url); + curlx_free(data->state.url); data->state.url = url; data->state.url_alloc = TRUE; } @@ -1810,7 +1806,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(data->state.url_alloc) - free(data->state.url); + curlx_free(data->state.url); data->state.url = newurl; data->state.url_alloc = TRUE; } @@ -1844,7 +1840,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, } /* make sure the connect struct gets its own copy of the hostname */ - conn->host.rawalloc = strdup(hostname ? hostname : ""); + conn->host.rawalloc = curlx_strdup(hostname ? hostname : ""); if(!conn->host.rawalloc) return CURLE_OUT_OF_MEMORY; conn->host.name = conn->host.rawalloc; @@ -1874,7 +1870,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, return Curl_uc_to_curlcode(uc); uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0); if(uc) { - free(url); + curlx_free(url); return Curl_uc_to_curlcode(uc); } data->state.url = url; @@ -1937,7 +1933,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data, uc = curl_url_get(uh, CURLUPART_OPTIONS, &data->state.up.options, CURLU_URLDECODE); if(!uc) { - conn->options = strdup(data->state.up.options); + conn->options = curlx_strdup(data->state.up.options); if(!conn->options) return CURLE_OUT_OF_MEMORY; } @@ -1993,12 +1989,12 @@ static CURLcode setup_range(struct Curl_easy *data) s->resume_from = data->set.set_resume_from; if(s->resume_from || data->set.str[STRING_SET_RANGE]) { if(s->rangestringalloc) - free(s->range); + curlx_free(s->range); if(s->resume_from) s->range = curl_maprintf("%" FMT_OFF_T "-", s->resume_from); else - s->range = strdup(data->set.str[STRING_SET_RANGE]); + s->range = curlx_strdup(data->set.str[STRING_SET_RANGE]); if(!s->range) return CURLE_OUT_OF_MEMORY; @@ -2261,7 +2257,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, goto error; if(proxyuser || proxypasswd) { - free(proxyinfo->user); + curlx_free(proxyinfo->user); proxyinfo->user = proxyuser; result = Curl_setstropt(&data->state.aptr.proxyuser, proxyuser); proxyuser = NULL; @@ -2269,7 +2265,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, goto error; Curl_safefree(proxyinfo->passwd); if(!proxypasswd) { - proxypasswd = strdup(""); + proxypasswd = curlx_strdup(""); if(!proxypasswd) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -2295,7 +2291,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, if(!curlx_str_number(&p, &num, UINT16_MAX)) proxyinfo->port = (uint16_t)num; /* Should we not error out when the port number is invalid? */ - free(portptr); + curlx_free(portptr); } else { if(data->set.proxyport) @@ -2326,13 +2322,13 @@ static CURLcode parse_proxy(struct Curl_easy *data, /* path will be "/", if no path was found */ if(strcmp("/", path)) { is_unix_proxy = TRUE; - free(host); + curlx_free(host); host = curl_maprintf(UNIX_SOCKET_PREFIX"%s", path); if(!host) { result = CURLE_OUT_OF_MEMORY; goto error; } - free(proxyinfo->host.rawalloc); + curlx_free(proxyinfo->host.rawalloc); proxyinfo->host.rawalloc = host; proxyinfo->host.name = host; host = NULL; @@ -2341,7 +2337,7 @@ static CURLcode parse_proxy(struct Curl_easy *data, if(!is_unix_proxy) { #endif - free(proxyinfo->host.rawalloc); + curlx_free(proxyinfo->host.rawalloc); proxyinfo->host.rawalloc = host; if(host[0] == '[') { /* this is a numerical IPv6, strip off the brackets */ @@ -2357,12 +2353,12 @@ static CURLcode parse_proxy(struct Curl_easy *data, #endif error: - free(proxyuser); - free(proxypasswd); - free(host); - free(scheme); + curlx_free(proxyuser); + curlx_free(proxypasswd); + curlx_free(host); + curlx_free(scheme); #ifdef USE_UNIX_SOCKETS - free(path); + curlx_free(path); #endif curl_url_cleanup(uhp); return result; @@ -2380,9 +2376,9 @@ static CURLcode parse_proxy_auth(struct Curl_easy *data, data->state.aptr.proxypasswd : ""; CURLcode result = CURLE_OUT_OF_MEMORY; - conn->http_proxy.user = strdup(proxyuser); + conn->http_proxy.user = curlx_strdup(proxyuser); if(conn->http_proxy.user) { - conn->http_proxy.passwd = strdup(proxypasswd); + conn->http_proxy.passwd = curlx_strdup(proxypasswd); if(conn->http_proxy.passwd) result = CURLE_OK; else @@ -2414,7 +2410,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, * Detect what (if any) proxy to use *************************************************************/ if(data->set.str[STRING_PROXY]) { - proxy = strdup(data->set.str[STRING_PROXY]); + proxy = curlx_strdup(data->set.str[STRING_PROXY]); /* if global proxy is set, this is it */ if(!proxy) { failf(data, "memory shortage"); @@ -2424,7 +2420,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, } if(data->set.str[STRING_PRE_PROXY]) { - socksproxy = strdup(data->set.str[STRING_PRE_PROXY]); + socksproxy = curlx_strdup(data->set.str[STRING_PRE_PROXY]); /* if global socks proxy is set, this is it */ if(!socksproxy) { failf(data, "memory shortage"); @@ -2460,20 +2456,21 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS /* For the time being do not mix proxy and Unix domain sockets. See #1274 */ if(proxy && conn->unix_domain_socket) { - free(proxy); + curlx_free(proxy); proxy = NULL; } #endif if(proxy && (!*proxy || (conn->handler->flags & PROTOPT_NONETWORK))) { - free(proxy); /* Do not bother with an empty proxy string or if the - protocol does not work with network */ + curlx_free(proxy); /* Do not bother with an empty proxy string + or if the protocol does not work with network */ proxy = NULL; } if(socksproxy && (!*socksproxy || (conn->handler->flags & PROTOPT_NONETWORK))) { - free(socksproxy); /* Do not bother with an empty socks proxy string or if - the protocol does not work with network */ + curlx_free(socksproxy); /* Do not bother with an empty socks proxy string + or if the protocol does not work with + network */ socksproxy = NULL; } @@ -2528,7 +2525,7 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, if(!conn->socks_proxy.user) { conn->socks_proxy.user = conn->http_proxy.user; conn->http_proxy.user = NULL; - free(conn->socks_proxy.passwd); + curlx_free(conn->socks_proxy.passwd); conn->socks_proxy.passwd = conn->http_proxy.passwd; conn->http_proxy.passwd = NULL; } @@ -2558,8 +2555,8 @@ static CURLcode create_conn_helper_init_proxy(struct Curl_easy *data, out: - free(socksproxy); - free(proxy); + curlx_free(socksproxy); + curlx_free(proxy); return result; } #endif /* CURL_DISABLE_PROXY */ @@ -2653,8 +2650,8 @@ CURLcode Curl_parse_login_details(const char *login, const size_t len, *passwdp = pbuf; return CURLE_OK; error: - free(ubuf); - free(pbuf); + curlx_free(ubuf); + curlx_free(pbuf); return CURLE_OUT_OF_MEMORY; } @@ -2712,8 +2709,8 @@ static CURLcode override_login(struct Curl_easy *data, char **optionsp = &conn->options; if(data->set.str[STRING_OPTIONS]) { - free(*optionsp); - *optionsp = strdup(data->set.str[STRING_OPTIONS]); + curlx_free(*optionsp); + *optionsp = curlx_strdup(data->set.str[STRING_OPTIONS]); if(!*optionsp) return CURLE_OUT_OF_MEMORY; } @@ -2767,14 +2764,14 @@ static CURLcode override_login(struct Curl_easy *data, } } if(url_provided) { - free(conn->user); - conn->user = strdup(*userp); + curlx_free(conn->user); + conn->user = curlx_strdup(*userp); if(!conn->user) return CURLE_OUT_OF_MEMORY; } /* no user was set but a password, set a blank user */ if(!*userp && *passwdp) { - *userp = strdup(""); + *userp = curlx_strdup(""); if(!*userp) return CURLE_OUT_OF_MEMORY; } @@ -2798,7 +2795,7 @@ static CURLcode override_login(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(!*userp) { - *userp = strdup(data->state.aptr.user); + *userp = curlx_strdup(data->state.aptr.user); if(!*userp) return CURLE_OUT_OF_MEMORY; } @@ -2815,7 +2812,7 @@ static CURLcode override_login(struct Curl_easy *data, if(uc) return Curl_uc_to_curlcode(uc); if(!*passwdp) { - *passwdp = strdup(data->state.aptr.passwd); + *passwdp = curlx_strdup(data->state.aptr.passwd); if(!*passwdp) return CURLE_OUT_OF_MEMORY; } @@ -2843,14 +2840,14 @@ static CURLcode set_login(struct Curl_easy *data, } /* Store the default user */ if(!conn->user) { - conn->user = strdup(setuser); + conn->user = curlx_strdup(setuser); if(!conn->user) return CURLE_OUT_OF_MEMORY; } /* Store the default password */ if(!conn->passwd) { - conn->passwd = strdup(setpasswd); + conn->passwd = curlx_strdup(setpasswd); if(!conn->passwd) result = CURLE_OUT_OF_MEMORY; } @@ -2885,7 +2882,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, if(!host || !*host) return CURLE_OK; - host_dup = strdup(host); + host_dup = curlx_strdup(host); if(!host_dup) return CURLE_OUT_OF_MEMORY; @@ -2947,7 +2944,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, /* now, clone the cleaned hostname */ DEBUGASSERT(hostptr); - *hostname_result = strdup(hostptr); + *hostname_result = curlx_strdup(hostptr); if(!*hostname_result) { result = CURLE_OUT_OF_MEMORY; goto error; @@ -2956,7 +2953,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data, *port_result = port; error: - free(host_dup); + curlx_free(host_dup); return result; } @@ -2995,7 +2992,7 @@ static CURLcode parse_connect_to_string(struct Curl_easy *data, hostname_to_match_len = strlen(hostname_to_match); host_match = curl_strnequal(ptr, hostname_to_match, hostname_to_match_len); - free(hostname_to_match); + curlx_free(hostname_to_match); ptr += hostname_to_match_len; host_match = host_match && *ptr == ':'; @@ -3136,7 +3133,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data, } if(hit) { - char *hostd = strdup((char *)as->dst.host); + char *hostd = curlx_strdup((char *)as->dst.host); if(!hostd) return CURLE_OUT_OF_MEMORY; conn->conn_to_host.rawalloc = hostd; @@ -3188,7 +3185,7 @@ static CURLcode resolve_unix(struct Curl_easy *data, /* Unix domain sockets are local. The host gets ignored, just use the * specified domain socket address. Do not cache "DNS entries". There is * no DNS involved and we already have the file system path available. */ - hostaddr = calloc(1, sizeof(struct Curl_dns_entry)); + hostaddr = curlx_calloc(1, sizeof(struct Curl_dns_entry)); if(!hostaddr) return CURLE_OUT_OF_MEMORY; @@ -3198,7 +3195,7 @@ static CURLcode resolve_unix(struct Curl_easy *data, if(longpath) /* Long paths are not supported for now */ failf(data, "Unix socket path too long: '%s'", unix_path); - free(hostaddr); + curlx_free(hostaddr); return longpath ? CURLE_COULDNT_RESOLVE_HOST : CURLE_OUT_OF_MEMORY; } @@ -3261,7 +3258,7 @@ static CURLcode resolve_server(struct Curl_easy *data, } /* Resolve target host right on */ - conn->hostname_resolve = strdup(ehost->name); + conn->hostname_resolve = curlx_strdup(ehost->name); if(!conn->hostname_resolve) return CURLE_OUT_OF_MEMORY; @@ -3308,8 +3305,8 @@ static void reuse_conn(struct Curl_easy *data, * be new for this request even when we reuse an existing connection */ if(temp->user) { /* use the new username and password though */ - free(existing->user); - free(existing->passwd); + curlx_free(existing->user); + curlx_free(existing->passwd); existing->user = temp->user; existing->passwd = temp->passwd; temp->user = NULL; @@ -3320,10 +3317,10 @@ static void reuse_conn(struct Curl_easy *data, existing->bits.proxy_user_passwd = temp->bits.proxy_user_passwd; if(existing->bits.proxy_user_passwd) { /* use the new proxy username and proxy password though */ - free(existing->http_proxy.user); - free(existing->socks_proxy.user); - free(existing->http_proxy.passwd); - free(existing->socks_proxy.passwd); + curlx_free(existing->http_proxy.user); + curlx_free(existing->socks_proxy.user); + curlx_free(existing->http_proxy.passwd); + curlx_free(existing->socks_proxy.passwd); existing->http_proxy.user = temp->http_proxy.user; existing->socks_proxy.user = temp->socks_proxy.user; existing->http_proxy.passwd = temp->http_proxy.passwd; @@ -3354,7 +3351,7 @@ static void reuse_conn(struct Curl_easy *data, existing->conn_to_port = temp->conn_to_port; existing->remote_port = temp->remote_port; - free(existing->hostname_resolve); + curlx_free(existing->hostname_resolve); existing->hostname_resolve = temp->hostname_resolve; temp->hostname_resolve = NULL; @@ -3436,7 +3433,7 @@ static CURLcode create_conn(struct Curl_easy *data, goto out; if(data->set.str[STRING_SASL_AUTHZID]) { - conn->sasl_authzid = strdup(data->set.str[STRING_SASL_AUTHZID]); + conn->sasl_authzid = curlx_strdup(data->set.str[STRING_SASL_AUTHZID]); if(!conn->sasl_authzid) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3444,7 +3441,7 @@ static CURLcode create_conn(struct Curl_easy *data, } if(data->set.str[STRING_BEARER]) { - conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]); + conn->oauth_bearer = curlx_strdup(data->set.str[STRING_BEARER]); if(!conn->oauth_bearer) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3453,7 +3450,8 @@ static CURLcode create_conn(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS if(data->set.str[STRING_UNIX_SOCKET_PATH]) { - conn->unix_domain_socket = strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); + conn->unix_domain_socket = + curlx_strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); if(!conn->unix_domain_socket) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -3924,7 +3922,7 @@ static void priority_remove_child(struct Curl_easy *parent, DEBUGASSERT(pnode); if(pnode) { *pnext = pnode->next; - free(pnode); + curlx_free(pnode); } child->set.priority.parent = 0; @@ -3943,7 +3941,7 @@ CURLcode Curl_data_priority_add_child(struct Curl_easy *parent, struct Curl_data_prio_node **tail; struct Curl_data_prio_node *pnode; - pnode = calloc(1, sizeof(*pnode)); + pnode = curlx_calloc(1, sizeof(*pnode)); if(!pnode) return CURLE_OUT_OF_MEMORY; pnode->data = child; diff --git a/lib/urlapi.c b/lib/urlapi.c index 9d3eb0f8cf..ad4d367dc3 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -37,10 +37,6 @@ #include "curlx/strparse.h" #include "curl_memrchr.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - #ifdef _WIN32 /* MS-DOS/Windows style drive prefix, eg c: in c:foo */ #define STARTS_WITH_DRIVE_PREFIX(str) \ @@ -94,16 +90,16 @@ static CURLUcode parseurl_and_replace(const char *url, CURLU *u, static void free_urlhandle(struct Curl_URL *u) { - free(u->scheme); - free(u->user); - free(u->password); - free(u->options); - free(u->host); - free(u->zoneid); - free(u->port); - free(u->path); - free(u->query); - free(u->fragment); + curlx_free(u->scheme); + curlx_free(u->user); + curlx_free(u->password); + curlx_free(u->options); + curlx_free(u->host); + curlx_free(u->zoneid); + curlx_free(u->port); + curlx_free(u->path); + curlx_free(u->query); + curlx_free(u->fragment); } /* @@ -384,17 +380,17 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, result = CURLUE_USER_NOT_ALLOWED; goto out; } - free(u->user); + curlx_free(u->user); u->user = userp; } if(passwdp) { - free(u->password); + curlx_free(u->password); u->password = passwdp; } if(optionsp) { - free(u->options); + curlx_free(u->options); u->options = optionsp; } @@ -404,9 +400,9 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, out: - free(userp); - free(passwdp); - free(optionsp); + curlx_free(userp); + curlx_free(passwdp); + curlx_free(optionsp); u->user = NULL; u->password = NULL; u->options = NULL; @@ -459,7 +455,7 @@ UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host, u->portnum = (unsigned short) port; /* generate a new port number string to get rid of leading zeroes etc */ - free(u->port); + curlx_free(u->port); u->port = curl_maprintf("%" CURL_FORMAT_CURL_OFF_T, port); if(!u->port) return CURLUE_OUT_OF_MEMORY; @@ -497,7 +493,7 @@ static CURLUcode ipv6_parse(struct Curl_URL *u, char *hostname, if(!i || (']' != *h)) return CURLUE_BAD_IPV6; zoneid[i] = 0; - u->zoneid = strdup(zoneid); + u->zoneid = curlx_strdup(zoneid); if(!u->zoneid) return CURLUE_OUT_OF_MEMORY; hostname[len] = ']'; /* insert end bracket */ @@ -675,7 +671,7 @@ static CURLUcode urldecode_host(struct dynbuf *host) return CURLUE_BAD_HOSTNAME; curlx_dyn_reset(host); result = curlx_dyn_addn(host, decoded, dlen); - free(decoded); + curlx_free(decoded); if(result) return cc2cu(result); } @@ -750,7 +746,7 @@ CURLUcode Curl_url_set_authority(CURLU *u, const char *authority) if(result) curlx_dyn_free(&host); else { - free(u->host); + curlx_free(u->host); u->host = curlx_dyn_ptr(&host); } return result; @@ -894,7 +890,7 @@ end: if(curlx_dyn_len(&out)) *outp = curlx_dyn_ptr(&out); else { - *outp = strdup(""); + *outp = curlx_strdup(""); if(!*outp) return 1; } @@ -940,7 +936,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) path = &url[5]; pathlen = urllen - 5; - u->scheme = strdup("file"); + u->scheme = curlx_strdup("file"); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1087,7 +1083,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) } if(schemep) { - u->scheme = strdup(schemep); + u->scheme = curlx_strdup(schemep); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1124,7 +1120,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) else schemep = "http"; - u->scheme = strdup(schemep); + u->scheme = curlx_strdup(schemep); if(!u->scheme) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1197,7 +1193,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) } else { /* single byte query */ - u->query = strdup(""); + u->query = curlx_strdup(""); if(!u->query) { result = CURLUE_OUT_OF_MEMORY; goto fail; @@ -1241,7 +1237,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) goto fail; } if(dedot) { - free(u->path); + curlx_free(u->path); u->path = dedot; } } @@ -1277,21 +1273,21 @@ static CURLUcode parseurl_and_replace(const char *url, CURLU *u, */ CURLU *curl_url(void) { - return calloc(1, sizeof(struct Curl_URL)); + return curlx_calloc(1, sizeof(struct Curl_URL)); } void curl_url_cleanup(CURLU *u) { if(u) { free_urlhandle(u); - free(u); + curlx_free(u); } } #define DUP(dest, src, name) \ do { \ if(src->name) { \ - dest->name = strdup(src->name); \ + dest->name = curlx_strdup(src->name); \ if(!dest->name) \ goto fail; \ } \ @@ -1299,7 +1295,7 @@ void curl_url_cleanup(CURLU *u) CURLU *curl_url_dup(const CURLU *in) { - struct Curl_URL *u = calloc(1, sizeof(struct Curl_URL)); + struct Curl_URL *u = curlx_calloc(1, sizeof(struct Curl_URL)); if(u) { DUP(u, in, scheme); DUP(u, in, user); @@ -1373,7 +1369,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, /* this unconditional rejection of control bytes is documented API behavior */ CURLcode res = Curl_urldecode(part, partlen, &decoded, &dlen, REJECT_CTRL); - free(part); + curlx_free(part); if(res) return CURLUE_URLDECODE; part = decoded; @@ -1383,7 +1379,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, struct dynbuf enc; curlx_dyn_init(&enc, CURL_MAX_INPUT_LENGTH); uc = urlencode_str(&enc, part, partlen, TRUE, what == CURLUPART_QUERY); - free(part); + curlx_free(part); if(uc) return uc; part = curlx_dyn_ptr(&enc); @@ -1392,7 +1388,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, if(!Curl_is_ASCII_name(u->host)) { char *punyversion = NULL; uc = host_decode(part, &punyversion); - free(part); + curlx_free(part); if(uc) return uc; part = punyversion; @@ -1402,7 +1398,7 @@ static CURLUcode urlget_format(const CURLU *u, CURLUPart what, if(Curl_is_ASCII_name(u->host)) { char *unpunified = NULL; uc = host_encode(part, &unpunified); - free(part); + curlx_free(part); if(uc) return uc; part = unpunified; @@ -1520,7 +1516,7 @@ static CURLUcode urlget_url(const CURLU *u, char **part, unsigned int flags) u->query ? u->query : "", show_fragment ? "#": "", u->fragment ? u->fragment : ""); - free(allochost); + curlx_free(allochost); } if(!url) return CURLUE_OUT_OF_MEMORY; @@ -1666,7 +1662,7 @@ static CURLUcode set_url_port(CURLU *u, const char *provided_port) tmp = curl_maprintf("%" CURL_FORMAT_CURL_OFF_T, port); if(!tmp) return CURLUE_OUT_OF_MEMORY; - free(u->port); + curlx_free(u->port); u->port = tmp; u->portnum = (unsigned short)port; return CURLUE_OK; @@ -1691,7 +1687,7 @@ static CURLUcode set_url(CURLU *u, const char *url, size_t part_size, if(!uc) { /* success, meaning the "" is a fine relative URL, but nothing changes */ - free(oldurl); + curlx_free(oldurl); return CURLUE_OK; } if(uc == CURLUE_OUT_OF_MEMORY) @@ -1715,7 +1711,7 @@ static CURLUcode set_url(CURLU *u, const char *url, size_t part_size, DEBUGASSERT(oldurl); /* it is set here */ /* apply the relative part to create a new URL */ uc = redirect_url(oldurl, url, u, flags); - free(oldurl); + curlx_free(oldurl); return uc; } @@ -1930,7 +1926,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what, if(curlx_dyn_add(&qbuf, newp)) goto nomem; curlx_dyn_free(&enc); - free(*storep); + curlx_free(*storep); *storep = curlx_dyn_ptr(&qbuf); return CURLUE_OK; nomem: @@ -1957,7 +1953,7 @@ nomem: Curl_urldecode(newp, n, &decoded, &dlen, REJECT_CTRL); if(result || hostname_check(u, decoded, dlen)) bad = TRUE; - free(decoded); + curlx_free(decoded); } else if(hostname_check(u, (char *)CURL_UNCONST(newp), n)) bad = TRUE; @@ -1968,7 +1964,7 @@ nomem: } } - free(*storep); + curlx_free(*storep); *storep = (char *)CURL_UNCONST(newp); } return CURLUE_OK; diff --git a/lib/vauth/cleartext.c b/lib/vauth/cleartext.c index 884ebce0f2..d259bc42b5 100644 --- a/lib/vauth/cleartext.c +++ b/lib/vauth/cleartext.c @@ -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() * diff --git a/lib/vauth/cram.c b/lib/vauth/cram.c index 2754ddc4a2..3b02e5751f 100644 --- a/lib/vauth/cram.c +++ b/lib/vauth/cram.c @@ -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() diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index 16045707fd..850891f175 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -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; diff --git a/lib/vauth/digest_sspi.c b/lib/vauth/digest_sspi.c index f730c52987..ea6a66af9f 100644 --- a/lib/vauth/digest_sspi.c +++ b/lib/vauth/digest_sspi.c @@ -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; } diff --git a/lib/vauth/gsasl.c b/lib/vauth/gsasl.c index 119c392cda..debeda0604 100644 --- a/lib/vauth/gsasl.c +++ b/lib/vauth/gsasl.c @@ -36,10 +36,6 @@ #include -/* 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) diff --git a/lib/vauth/krb5_gssapi.c b/lib/vauth/krb5_gssapi.c index a414d0a359..9ea36171fa 100644 --- a/lib/vauth/krb5_gssapi.c +++ b/lib/vauth/krb5_gssapi.c @@ -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; } diff --git a/lib/vauth/krb5_sspi.c b/lib/vauth/krb5_sspi.c index cad2412d17..10fbac7644 100644 --- a/lib/vauth/krb5_sspi.c +++ b/lib/vauth/krb5_sspi.c @@ -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; } diff --git a/lib/vauth/ntlm.c b/lib/vauth/ntlm.c index 1e9b629d8f..a757d1c8f9 100644 --- a/lib/vauth/ntlm.c +++ b/lib/vauth/ntlm.c @@ -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); diff --git a/lib/vauth/ntlm_sspi.c b/lib/vauth/ntlm_sspi.c index 071617182e..d976bc5d21 100644 --- a/lib/vauth/ntlm_sspi.c +++ b/lib/vauth/ntlm_sspi.c @@ -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; } diff --git a/lib/vauth/oauth2.c b/lib/vauth/oauth2.c index cf7addf535..0bb7a9d6bd 100644 --- a/lib/vauth/oauth2.c +++ b/lib/vauth/oauth2.c @@ -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() * diff --git a/lib/vauth/spnego_gssapi.c b/lib/vauth/spnego_gssapi.c index 4e9125ba44..f956f2c03e 100644 --- a/lib/vauth/spnego_gssapi.c +++ b/lib/vauth/spnego_gssapi.c @@ -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) { diff --git a/lib/vauth/spnego_sspi.c b/lib/vauth/spnego_sspi.c index b36535557b..90e622da3d 100644 --- a/lib/vauth/spnego_sspi.c +++ b/lib/vauth/spnego_sspi.c @@ -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; } diff --git a/lib/vauth/vauth.c b/lib/vauth/vauth.c index 6ee687dcab..6626ace8bc 100644 --- a/lib/vauth/vauth.c +++ b/lib/vauth/vauth.c @@ -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; diff --git a/lib/vquic/curl_ngtcp2.c b/lib/vquic/curl_ngtcp2.c index 86f7428048..4767780a92 100644 --- a/lib/vquic/curl_ngtcp2.c +++ b/lib/vquic/curl_ngtcp2.c @@ -71,10 +71,6 @@ #include "../curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define QUIC_MAX_STREAMS (256*1024) #define QUIC_HANDSHAKE_TIMEOUT (10*NGTCP2_SECONDS) @@ -182,7 +178,7 @@ static void cf_ngtcp2_ctx_free(struct cf_ngtcp2_ctx *ctx) Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); } - free(ctx); + curlx_free(ctx); } static void cf_ngtcp2_setup_keep_alive(struct Curl_cfilter *cf, @@ -255,7 +251,7 @@ static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->sendbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -277,7 +273,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -1573,7 +1569,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(nghttp3_nv) * nheader); + nva = curlx_malloc(sizeof(nghttp3_nv) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1650,7 +1646,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } @@ -2851,7 +2847,7 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vquic/curl_osslq.c b/lib/vquic/curl_osslq.c index d6672ce132..1c3f0c55b6 100644 --- a/lib/vquic/curl_osslq.c +++ b/lib/vquic/curl_osslq.c @@ -57,10 +57,6 @@ #include "../curlx/warnless.h" #include "../curlx/strerr.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* A stream window is the maximum amount we need to buffer for * each active transfer. We use HTTP/3 flow control and only ACK * when we take things out of the buffer. @@ -318,10 +314,10 @@ static void cf_osslq_ctx_free(struct cf_osslq_ctx *ctx) Curl_bufcp_free(&ctx->stream_bufcp); Curl_uint32_hash_destroy(&ctx->streams); Curl_ssl_peer_cleanup(&ctx->peer); - free(ctx->poll_items); - free(ctx->curl_items); + curlx_free(ctx->poll_items); + curlx_free(ctx->curl_items); } - free(ctx); + curlx_free(ctx); } static void cf_osslq_ctx_close(struct cf_osslq_ctx *ctx) @@ -596,7 +592,7 @@ static void h3_stream_ctx_free(struct h3_stream_ctx *stream) Curl_bufq_free(&stream->sendbuf); Curl_bufq_free(&stream->recvbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -618,7 +614,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -1511,18 +1507,19 @@ static CURLcode cf_osslq_check_and_unblock(struct Curl_cfilter *cf, if(ctx->items_max < Curl_uint32_hash_count(&ctx->streams)) { size_t nmax = Curl_uint32_hash_count(&ctx->streams); ctx->items_max = 0; - tmpptr = realloc(ctx->poll_items, nmax * sizeof(SSL_POLL_ITEM)); + tmpptr = curlx_realloc(ctx->poll_items, nmax * sizeof(SSL_POLL_ITEM)); if(!tmpptr) { - free(ctx->poll_items); + curlx_free(ctx->poll_items); ctx->poll_items = NULL; res = CURLE_OUT_OF_MEMORY; goto out; } ctx->poll_items = tmpptr; - tmpptr = realloc(ctx->curl_items, nmax * sizeof(struct Curl_easy *)); + tmpptr = curlx_realloc(ctx->curl_items, + nmax * sizeof(struct Curl_easy *)); if(!tmpptr) { - free(ctx->curl_items); + curlx_free(ctx->curl_items); ctx->curl_items = NULL; res = CURLE_OUT_OF_MEMORY; goto out; @@ -1922,7 +1919,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(nghttp3_nv) * nheader); + nva = curlx_malloc(sizeof(nghttp3_nv) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1999,7 +1996,7 @@ static CURLcode h3_stream_open(struct Curl_cfilter *cf, } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } @@ -2407,7 +2404,7 @@ CURLcode Curl_cf_osslq_create(struct Curl_cfilter **pcf, CURLcode result; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vquic/curl_quiche.c b/lib/vquic/curl_quiche.c index f8fbadeebb..c182e1490d 100644 --- a/lib/vquic/curl_quiche.c +++ b/lib/vquic/curl_quiche.c @@ -52,10 +52,6 @@ #include "../vtls/keylog.h" #include "../vtls/vtls.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* HTTP/3 error values defined in RFC 9114, ch. 8.1 */ #define CURL_H3_NO_ERROR (0x0100) @@ -141,7 +137,7 @@ static void cf_quiche_ctx_free(struct cf_quiche_ctx *ctx) Curl_bufcp_free(&ctx->stream_bufcp); Curl_uint32_hash_destroy(&ctx->streams); } - free(ctx); + curlx_free(ctx); } static void cf_quiche_ctx_close(struct cf_quiche_ctx *ctx) @@ -188,7 +184,7 @@ static void h3_stream_ctx_free(struct h3_stream_ctx *stream) { Curl_bufq_free(&stream->recvbuf); Curl_h1_req_parse_free(&stream->h1); - free(stream); + curlx_free(stream); } static void h3_stream_hash_free(unsigned int id, void *stream) @@ -269,7 +265,7 @@ static CURLcode h3_data_setup(struct Curl_cfilter *cf, if(stream) return CURLE_OK; - stream = calloc(1, sizeof(*stream)); + stream = curlx_calloc(1, sizeof(*stream)); if(!stream) return CURLE_OUT_OF_MEMORY; @@ -1000,7 +996,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, Curl_h1_req_parse_free(&stream->h1); nheader = Curl_dynhds_count(&h2_headers); - nva = malloc(sizeof(quiche_h3_header) * nheader); + nva = curlx_malloc(sizeof(quiche_h3_header) * nheader); if(!nva) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1070,7 +1066,7 @@ static CURLcode h3_open_stream(struct Curl_cfilter *cf, } out: - free(nva); + curlx_free(nva); Curl_dynhds_free(&h2_headers); return result; } @@ -1633,7 +1629,7 @@ CURLcode Curl_cf_quiche_create(struct Curl_cfilter **pcf, (void)data; (void)conn; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vquic/vquic-tls.c b/lib/vquic/vquic-tls.c index 46bb4c7d4c..7a3c99b584 100644 --- a/lib/vquic/vquic-tls.c +++ b/lib/vquic/vquic-tls.c @@ -53,10 +53,6 @@ #include "../vtls/vtls_scache.h" #include "vquic-tls.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - CURLcode Curl_vquic_tls_init(struct curl_tls_ctx *ctx, struct Curl_cfilter *cf, struct Curl_easy *data, diff --git a/lib/vquic/vquic.c b/lib/vquic/vquic.c index 8b4d678d81..c1267cef9e 100644 --- a/lib/vquic/vquic.c +++ b/lib/vquic/vquic.c @@ -47,10 +47,6 @@ #include "../curlx/strerr.h" #include "../curlx/strparse.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3) @@ -675,7 +671,7 @@ CURLcode Curl_qlogdir(struct Curl_easy *data, *qlogfdp = qlogfd; } curlx_dyn_free(&fname); - free(qlog_dir); + curlx_free(qlog_dir); if(result) return result; } diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 4b003bd71c..a5997a6f6c 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -72,10 +72,6 @@ #include #endif -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* A recent macro provided by libssh. Or make our own. */ #ifndef SSH_STRING_FREE_CHAR #define SSH_STRING_FREE_CHAR(x) \ @@ -491,10 +487,12 @@ static int myssh_is_known(struct Curl_easy *data, struct ssh_conn *sshc) cleanup: if(found_base64) { - (free)(found_base64); + /* !checksrc! disable BANNEDFUNC 1 */ + free(found_base64); /* allocated by libssh, deallocate with system free */ } if(known_base64) { - (free)(known_base64); + /* !checksrc! disable BANNEDFUNC 1 */ + free(known_base64); /* allocated by libssh, deallocate with system free */ } if(hash) ssh_clean_pubkey_hash(&hash); @@ -605,7 +603,7 @@ static int myssh_in_SFTP_READDIR(struct Curl_easy *data, } result = Curl_client_write(data, CLIENTWRITE_BODY, tmpLine, sshc->readdir_len + 1); - free(tmpLine); + curlx_free(tmpLine); if(result) { myssh_to(data, sshc, SSH_STOP); @@ -787,7 +785,7 @@ static int myssh_in_SFTP_QUOTE_STATVFS(struct Curl_easy *data, if(!result) { result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); } if(result) { myssh_to(data, sshc, SSH_SFTP_CLOSE); @@ -1478,8 +1476,8 @@ static int myssh_in_SFTP_REALPATH(struct Curl_easy *data, if(!sshc->homedir) return myssh_to_ERROR(data, sshc, CURLE_COULDNT_CONNECT); - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(sshc->homedir); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(sshc->homedir); if(!data->state.most_recent_ftp_entrypath) return myssh_to_ERROR(data, sshc, CURLE_OUT_OF_MEMORY); @@ -1577,7 +1575,7 @@ static int myssh_in_SFTP_QUOTE(struct Curl_easy *data, the current directory can be read similar to how it is read when using ordinary FTP. */ result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(result) { myssh_to(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; @@ -2529,7 +2527,7 @@ static void myssh_easy_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; Curl_safefree(sshp->path); - free(sshp); + curlx_free(sshp); } static void myssh_conn_dtor(void *key, size_t klen, void *entry) @@ -2538,7 +2536,7 @@ static void myssh_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; sshc_cleanup(sshc); - free(sshc); + curlx_free(sshc); } /* @@ -2550,7 +2548,7 @@ static CURLcode myssh_setup_connection(struct Curl_easy *data, struct SSHPROTO *sshp; struct ssh_conn *sshc; - sshc = calloc(1, sizeof(*sshc)); + sshc = curlx_calloc(1, sizeof(*sshc)); if(!sshc) return CURLE_OUT_OF_MEMORY; @@ -2559,7 +2557,7 @@ static CURLcode myssh_setup_connection(struct Curl_easy *data, if(Curl_conn_meta_set(conn, CURL_META_SSH_CONN, sshc, myssh_conn_dtor)) return CURLE_OUT_OF_MEMORY; - sshp = calloc(1, sizeof(*sshp)); + sshp = curlx_calloc(1, sizeof(*sshp)); if(!sshp || Curl_meta_set(data, CURL_META_SSH_EASY, sshp, myssh_easy_dtor)) return CURLE_OUT_OF_MEMORY; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index e4ceda8c34..4ac9d89f1a 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -66,10 +66,6 @@ #include "../curlx/strparse.h" #include "../curlx/base64.h" /* for base64 encoding/decoding */ -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* Local functions: */ static const char *sftp_libssh2_strerror(unsigned long err); static LIBSSH2_ALLOC_FUNC(my_libssh2_malloc); @@ -181,7 +177,7 @@ kbd_callback(const char *name, int name_len, const char *instruction, #endif /* CURL_LIBSSH2_DEBUG */ if(num_prompts == 1) { struct connectdata *conn = data->conn; - responses[0].text = strdup(conn->passwd); + responses[0].text = curlx_strdup(conn->passwd); responses[0].length = responses[0].text == NULL ? 0 : curlx_uztoui(strlen(conn->passwd)); } @@ -635,12 +631,12 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data, failf(data, "Denied establishing ssh session: mismatch sha256 fingerprint. " "Remote %s is not equal to %s", fingerprint_b64, pubkey_sha256); - free(fingerprint_b64); + curlx_free(fingerprint_b64); myssh_state(data, sshc, SSH_SESSION_FREE); return CURLE_PEER_FAILED_VERIFICATION; } - free(fingerprint_b64); + curlx_free(fingerprint_b64); infof(data, "SHA256 checksum match"); } @@ -881,7 +877,7 @@ static CURLcode sftp_quote(struct Curl_easy *data, the current directory can be read similar to how it is read when using ordinary FTP. */ result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(!result) myssh_state(data, sshc, SSH_SFTP_NEXT_QUOTE); return result; @@ -1204,7 +1200,7 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, sshc->rsa_pub = sshc->rsa = NULL; if(data->set.str[STRING_SSH_PRIVATE_KEY]) - sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); + sshc->rsa = curlx_strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); else { /* To ponder about: should really the lib be messing about with the HOME environment variable etc? */ @@ -1218,7 +1214,7 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, if(!sshc->rsa) out_of_memory = TRUE; else if(curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); + curlx_free(sshc->rsa); sshc->rsa = curl_maprintf("%s/.ssh/id_dsa", home); if(!sshc->rsa) out_of_memory = TRUE; @@ -1226,19 +1222,19 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, Curl_safefree(sshc->rsa); } } - free(home); + curlx_free(home); } if(!out_of_memory && !sshc->rsa) { /* Nothing found; try the current dir. */ - sshc->rsa = strdup("id_rsa"); + sshc->rsa = curlx_strdup("id_rsa"); if(sshc->rsa && curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); - sshc->rsa = strdup("id_dsa"); + curlx_free(sshc->rsa); + sshc->rsa = curlx_strdup("id_dsa"); if(sshc->rsa && curlx_stat(sshc->rsa, &sbuf)) { - free(sshc->rsa); + curlx_free(sshc->rsa); /* Out of guesses. Set to the empty string to avoid * surprising info messages. */ - sshc->rsa = strdup(""); + sshc->rsa = curlx_strdup(""); } } } @@ -1252,7 +1248,7 @@ static CURLcode ssh_state_pkey_init(struct Curl_easy *data, if(data->set.str[STRING_SSH_PUBLIC_KEY] /* treat empty string the same way as NULL */ && data->set.str[STRING_SSH_PUBLIC_KEY][0]) { - sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); + sshc->rsa_pub = curlx_strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); if(!sshc->rsa_pub) out_of_memory = TRUE; } @@ -1936,12 +1932,12 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, myssh_state(data, sshc, SSH_STOP); if(rc > 0) { - free(sshc->homedir); - sshc->homedir = strdup(sshp->readdir_filename); + curlx_free(sshc->homedir); + sshc->homedir = curlx_strdup(sshp->readdir_filename); if(!sshc->homedir) return CURLE_OUT_OF_MEMORY; - free(data->state.most_recent_ftp_entrypath); - data->state.most_recent_ftp_entrypath = strdup(sshc->homedir); + curlx_free(data->state.most_recent_ftp_entrypath); + data->state.most_recent_ftp_entrypath = curlx_strdup(sshc->homedir); if(!data->state.most_recent_ftp_entrypath) return CURLE_OUT_OF_MEMORY; } @@ -2251,7 +2247,7 @@ static CURLcode ssh_state_sftp_quote_statvfs(struct Curl_easy *data, } result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); - free(tmp); + curlx_free(tmp); if(result) { myssh_state(data, sshc, SSH_SFTP_CLOSE); sshc->nextstate = SSH_NO_STATE; @@ -3177,7 +3173,7 @@ static void myssh_easy_dtor(void *key, size_t klen, void *entry) Curl_safefree(sshp->path); curlx_dyn_free(&sshp->readdir); curlx_dyn_free(&sshp->readdir_link); - free(sshp); + curlx_free(sshp); } static void myssh_conn_dtor(void *key, size_t klen, void *entry) @@ -3186,7 +3182,7 @@ static void myssh_conn_dtor(void *key, size_t klen, void *entry) (void)key; (void)klen; sshc_cleanup(sshc, NULL, TRUE); - free(sshc); + curlx_free(sshc); } /* @@ -3199,14 +3195,14 @@ static CURLcode ssh_setup_connection(struct Curl_easy *data, struct SSHPROTO *sshp; (void)conn; - sshc = calloc(1, sizeof(*sshc)); + sshc = curlx_calloc(1, sizeof(*sshc)); if(!sshc) return CURLE_OUT_OF_MEMORY; if(Curl_conn_meta_set(conn, CURL_META_SSH_CONN, sshc, myssh_conn_dtor)) return CURLE_OUT_OF_MEMORY; - sshp = calloc(1, sizeof(*sshp)); + sshp = curlx_calloc(1, sizeof(*sshp)); if(!sshp) return CURLE_OUT_OF_MEMORY; diff --git a/lib/vssh/vssh.c b/lib/vssh/vssh.c index e33386a16a..a23f9e8e98 100644 --- a/lib/vssh/vssh.c +++ b/lib/vssh/vssh.c @@ -30,9 +30,7 @@ #include #include "../curlx/strparse.h" #include "../curl_trc.h" -#include "../curl_memory.h" #include "../escape.h" -#include "../memdebug.h" #define MAX_SSHPATH_LEN 100000 /* arbitrary */ @@ -59,7 +57,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, (working_path_len > 3) && (!memcmp(working_path, "/~/", 3))) { /* It is referenced to the home directory, so strip the leading '/~/' */ if(curlx_dyn_addn(&npath, &working_path[3], working_path_len - 3)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } @@ -67,7 +65,7 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, (!strcmp("/~", working_path) || ((working_path_len > 2) && !memcmp(working_path, "/~/", 3)))) { if(curlx_dyn_add(&npath, homedir)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } if(working_path_len > 2) { @@ -82,20 +80,20 @@ CURLcode Curl_getworkingpath(struct Curl_easy *data, if(curlx_dyn_addn(&npath, &working_path[copyfrom], working_path_len - copyfrom)) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } else { if(curlx_dyn_add(&npath, "/")) { - free(working_path); + curlx_free(working_path); return CURLE_OUT_OF_MEMORY; } } } if(curlx_dyn_len(&npath)) { - free(working_path); + curlx_free(working_path); /* store the pointer for the caller to receive */ *path = curlx_dyn_ptr(&npath); diff --git a/lib/vtls/apple.c b/lib/vtls/apple.c index 297ebc39f3..62bb9e3bd1 100644 --- a/lib/vtls/apple.c +++ b/lib/vtls/apple.c @@ -50,10 +50,6 @@ #include #endif -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifdef USE_APPLE_SECTRUST #define SSL_SYSTEM_VERIFIER @@ -244,11 +240,11 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, if(error_ref) { CFIndex size = CFStringGetMaximumSizeForEncoding( CFStringGetLength(error_ref), kCFStringEncodingUTF8); - err_desc = malloc(size + 1); + err_desc = curlx_malloc(size + 1); if(err_desc) { if(!CFStringGetCString(error_ref, err_desc, size, kCFStringEncodingUTF8)) { - free(err_desc); + curlx_free(err_desc); err_desc = NULL; } } @@ -276,7 +272,7 @@ CURLcode Curl_vtls_apple_verify(struct Curl_cfilter *cf, } out: - free(err_desc); + curlx_free(err_desc); if(error_ref) CFRelease(error_ref); if(error) diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index 55a75fa721..c05ab8427b 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -59,9 +59,6 @@ #include "../curlx/warnless.h" #include "x509asn1.h" #include "../multiif.h" -#include "../curl_memory.h" -/* The last #include file should be: */ -#include "../memdebug.h" /* Enable GnuTLS debugging by defining GTLSDEBUG */ /*#define GTLSDEBUG */ @@ -215,10 +212,10 @@ static gnutls_datum_t load_file(const char *file) if(fseek(f, 0, SEEK_END) != 0 || (filelen = ftell(f)) < 0 || fseek(f, 0, SEEK_SET) != 0 - || !(ptr = malloc((size_t)filelen))) + || !(ptr = curlx_malloc((size_t)filelen))) goto out; if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { - free(ptr); + curlx_free(ptr); goto out; } @@ -231,7 +228,7 @@ out: static void unload_file(gnutls_datum_t data) { - free(data.data); + curlx_free(data.data); } @@ -404,14 +401,14 @@ CURLcode Curl_gtls_shared_creds_create(struct Curl_easy *data, int rc; *pcreds = NULL; - shared = calloc(1, sizeof(*shared)); + shared = curlx_calloc(1, sizeof(*shared)); if(!shared) return CURLE_OUT_OF_MEMORY; rc = gnutls_certificate_allocate_credentials(&shared->creds); if(rc != GNUTLS_E_SUCCESS) { failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc)); - free(shared); + curlx_free(shared); return CURLE_SSL_CONNECT_ERROR; } @@ -439,8 +436,8 @@ void Curl_gtls_shared_creds_free(struct gtls_shared_creds **pcreds) --shared->refcount; if(!shared->refcount) { gnutls_certificate_free_credentials(shared->creds); - free(shared->CAfile); - free(shared); + curlx_free(shared->CAfile); + curlx_free(shared); } } } @@ -629,7 +626,7 @@ static void gtls_set_cached_creds(struct Curl_cfilter *cf, return; if(conn_config->CAfile) { - sc->CAfile = strdup(conn_config->CAfile); + sc->CAfile = curlx_strdup(conn_config->CAfile); if(!sc->CAfile) return; } @@ -723,7 +720,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, if(!sdata_len) /* gnutls does this for some version combinations */ return CURLE_OK; - sdata = malloc(sdata_len); /* get a buffer for it */ + sdata = curlx_malloc(sdata_len); /* get a buffer for it */ if(!sdata) return CURLE_OUT_OF_MEMORY; @@ -737,7 +734,7 @@ CURLcode Curl_gtls_cache_session(struct Curl_cfilter *cf, if(quic_tp && quic_tp_len) { qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); if(!qtp_clone) { - free(sdata); + curlx_free(sdata); return CURLE_OUT_OF_MEMORY; } } @@ -1312,7 +1309,7 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data, if(ret != GNUTLS_E_SHORT_MEMORY_BUFFER || len1 == 0) break; /* failed */ - buff1 = malloc(len1); + buff1 = curlx_malloc(len1); if(!buff1) break; /* failed */ diff --git a/lib/vtls/hostcheck.c b/lib/vtls/hostcheck.c index 23ba33951f..672f473db4 100644 --- a/lib/vtls/hostcheck.c +++ b/lib/vtls/hostcheck.c @@ -37,10 +37,6 @@ #include "hostcheck.h" #include "../hostip.h" -#include "../curl_memory.h" -/* The last #include file should be: */ -#include "../memdebug.h" - /* check the two input strings with given length, but do not assume they end in nul-bytes */ static bool pmatch(const char *hostname, size_t hostlen, diff --git a/lib/vtls/keylog.c b/lib/vtls/keylog.c index 9179d38fe7..397bac1a36 100644 --- a/lib/vtls/keylog.c +++ b/lib/vtls/keylog.c @@ -35,10 +35,6 @@ #include "../escape.h" #include "../curlx/fopen.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* The fp for the open SSLKEYLOGFILE, or NULL if not open */ static FILE *keylog_file_fp; diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c index 2ea3670c1b..9e13ed4641 100644 --- a/lib/vtls/mbedtls.c +++ b/lib/vtls/mbedtls.c @@ -75,10 +75,6 @@ #include "../strdup.h" #include "../curl_sha256.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* ALPN for http2 */ #if defined(USE_HTTP2) && defined(MBEDTLS_SSL_ALPN) # define HAS_ALPN_MBEDTLS @@ -355,7 +351,7 @@ mbed_set_selected_ciphers(struct Curl_easy *data, for(i = 0; supported[i] != 0; i++); supported_len = i; - selected = malloc(sizeof(int) * (supported_len + 1)); + selected = curlx_malloc(sizeof(int) * (supported_len + 1)); if(!selected) return CURLE_OUT_OF_MEMORY; @@ -433,7 +429,7 @@ add_ciphers: selected[count] = 0; if(count == 0) { - free(selected); + curlx_free(selected); failf(data, "mbedTLS: no supported cipher in list"); return CURLE_SSL_CIPHER; } @@ -452,7 +448,7 @@ mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) (void)data, (void)crt; #else const size_t bufsize = 16384; - char *p, *buffer = malloc(bufsize); + char *p, *buffer = curlx_malloc(bufsize); if(buffer && mbedtls_x509_crt_info(buffer, bufsize, " ", crt) > 0) { infof(data, "Server certificate:"); @@ -465,7 +461,7 @@ mbed_dump_cert_info(struct Curl_easy *data, const mbedtls_x509_crt *crt) else infof(data, "Unable to dump certificate information"); - free(buffer); + curlx_free(buffer); #endif } @@ -597,7 +593,7 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OUT_OF_MEMORY; ret = mbedtls_x509_crt_parse(&backend->cacert, newblob, ca_info_blob->len + 1); - free(newblob); + curlx_free(newblob); if(ret < 0) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); failf(data, "Error importing ca cert blob - mbedTLS: (-0x%04X) %s", @@ -670,7 +666,7 @@ mbed_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_OUT_OF_MEMORY; ret = mbedtls_x509_crt_parse(&backend->clicert, newblob, ssl_cert_blob->len + 1); - free(newblob); + curlx_free(newblob); if(ret) { mbedtls_strerror(ret, errorbuf, sizeof(errorbuf)); @@ -1027,12 +1023,12 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_SSL_PINNEDPUBKEYNOTMATCH; } - p = calloc(1, sizeof(*p)); + p = curlx_calloc(1, sizeof(*p)); if(!p) return CURLE_OUT_OF_MEMORY; - pubkey = malloc(PUB_DER_MAX_BYTES); + pubkey = curlx_malloc(PUB_DER_MAX_BYTES); if(!pubkey) { result = CURLE_OUT_OF_MEMORY; @@ -1064,8 +1060,8 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) &pubkey[PUB_DER_MAX_BYTES - size], size); pinnedpubkey_error: mbedtls_x509_crt_free(p); - free(p); - free(pubkey); + curlx_free(p); + curlx_free(pubkey); if(result) return result; } @@ -1122,7 +1118,7 @@ mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) goto out; } - sdata = malloc(slen); + sdata = curlx_malloc(slen); if(!sdata) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -1147,7 +1143,7 @@ mbed_new_session(struct Curl_cfilter *cf, struct Curl_easy *data) out: if(msession_alloced) mbedtls_ssl_session_free(&session); - free(sdata); + curlx_free(sdata); return result; } diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c index 82590929cd..91de9eceb5 100644 --- a/lib/vtls/mbedtls_threadlock.c +++ b/lib/vtls/mbedtls_threadlock.c @@ -37,10 +37,6 @@ #include "mbedtls_threadlock.h" -/* The last 2 #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* number of thread locks */ #define NUMT 2 diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index d8f99b21c3..bdfe527acd 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -132,10 +132,6 @@ static void ossl_provider_cleanup(struct Curl_easy *data); #include "../curlx/warnless.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #if defined(USE_OPENSSL_ENGINE) || defined(OPENSSL_HAS_PROVIDERS) #include #endif @@ -1831,7 +1827,7 @@ static CURLcode ossl_set_provider(struct Curl_easy *data, const char *iname) if(!libctx) return CURLE_OUT_OF_MEMORY; if(propq) { - data->state.propq = strdup(propq); + data->state.propq = curlx_strdup(propq); if(!data->state.propq) { OSSL_LIB_CTX_free(libctx); return CURLE_OUT_OF_MEMORY; @@ -2738,7 +2734,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, goto out; } - der_session_buf = der_session_ptr = malloc(der_session_size); + der_session_buf = der_session_ptr = curlx_malloc(der_session_size); if(!der_session_buf) { result = CURLE_OUT_OF_MEMORY; goto out; @@ -2775,7 +2771,7 @@ CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf, } out: - free(der_session_buf); + curlx_free(der_session_buf); return result; } @@ -2932,7 +2928,7 @@ static CURLcode ossl_win_load_store(struct Curl_easy *data, */ if(CertGetEnhancedKeyUsage(pContext, 0, NULL, &req_size)) { if(req_size && req_size > enhkey_usage_size) { - void *tmp = realloc(enhkey_usage, req_size); + void *tmp = curlx_realloc(enhkey_usage, req_size); if(!tmp) { failf(data, "SSL: Out of memory allocating for OID list"); @@ -2990,7 +2986,7 @@ static CURLcode ossl_win_load_store(struct Curl_easy *data, X509_free(x509); } - free(enhkey_usage); + curlx_free(enhkey_usage); CertFreeCertificateContext(pContext); CertCloseStore(hStore, 0); @@ -3233,8 +3229,8 @@ static void oss_x509_share_free(void *key, size_t key_len, void *p) if(share->store) { X509_STORE_free(share->store); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } static bool @@ -3304,14 +3300,14 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, sizeof(MPROTO_OSSL_X509_KEY)-1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), sizeof(MPROTO_OSSL_X509_KEY)-1, share, oss_x509_share_free)) { - free(share); + curlx_free(share); return; } } @@ -3320,7 +3316,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, char *CAfile = NULL; if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { X509_STORE_free(store); return; @@ -3329,7 +3325,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, if(share->store) { X509_STORE_free(share->store); - free(share->CAfile); + curlx_free(share->CAfile); } share->time = curlx_now(); @@ -3516,11 +3512,11 @@ static CURLcode ossl_init_ech(struct ossl_ctx *octx, ech_config_len) != 1) { infof(data, "ECH: SSL_ECH_set1_ech_config_list failed"); if(data->set.tls_ech & CURLECH_HARD) { - free(ech_config); + curlx_free(ech_config); return CURLE_SSL_CONNECT_ERROR; } } - free(ech_config); + curlx_free(ech_config); trying_ech_now = 1; # else ech_config = (unsigned char *) data->set.str[STRING_ECH_CONFIG]; @@ -4160,7 +4156,7 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl, result = curlx_base64_encode(rcs, rcl, &b64str, &blen); if(!result && b64str) { infof(data, "ECH: retry_configs %s", b64str); - free(b64str); + curlx_free(b64str); #ifndef HAVE_BORINGSSL_LIKE rv = SSL_ech_get1_status(ssl, &inner, &outer); infof(data, "ECH: retry_configs for %s from %s, %d %d", @@ -4446,7 +4442,7 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, if(len1 < 1) break; /* failed */ - buff1 = temp = malloc(len1); + buff1 = temp = curlx_malloc(len1); if(!buff1) break; /* failed */ @@ -4468,7 +4464,7 @@ static CURLcode ossl_pkp_pin_peer_pubkey(struct Curl_easy *data, X509* cert, } while(0); if(buff1) - free(buff1); + curlx_free(buff1); return result; } diff --git a/lib/vtls/rustls.c b/lib/vtls/rustls.c index cc19a328ed..e4251a9151 100644 --- a/lib/vtls/rustls.c +++ b/lib/vtls/rustls.c @@ -42,10 +42,6 @@ #include "cipher_suite.h" #include "x509asn1.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - struct rustls_ssl_backend_data { const struct rustls_client_config *config; @@ -586,7 +582,7 @@ init_config_builder(struct Curl_easy *data, } #endif /* USE_ECH */ - cipher_suites = malloc(sizeof(*cipher_suites) * (cipher_suites_len)); + cipher_suites = curlx_malloc(sizeof(*cipher_suites) * (cipher_suites_len)); if(!cipher_suites) { result = CURLE_OUT_OF_MEMORY; goto cleanup; @@ -643,7 +639,7 @@ init_config_builder(struct Curl_easy *data, cleanup: if(cipher_suites) { - free(cipher_suites); + curlx_free(cipher_suites); } if(custom_provider_builder) { rustls_crypto_provider_builder_free(custom_provider_builder); @@ -1004,7 +1000,7 @@ init_config_builder_ech(struct Curl_easy *data, cleanup: /* if we base64 decoded, we can free now */ if(data->set.tls_ech & CURLECH_CLA_CFG && data->set.str[STRING_ECH_CONFIG]) { - free(ech_config); + curlx_free(ech_config); } if(dns) { Curl_resolv_unlink(data, &dns); diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index e5fbe40a8c..49a4516cdf 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -60,10 +60,6 @@ #include "../progress.h" #include "../curl_sha256.h" -/* The last #include file should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* Some verbose debug messages are wrapped by SCH_DEV() instead of DEBUGF() * and only shown if CURL_SCHANNEL_DEV_DEBUG was defined at build time. These * messages are extra verbose and intended for curl developers debugging @@ -427,7 +423,7 @@ get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path, return CURLE_SSL_CERTPROBLEM; *sep = TEXT('\0'); - *store_path = Curl_tcsdup(store_path_start); + *store_path = curlx_tcsdup(store_path_start); *sep = TEXT('\\'); if(!*store_path) return CURLE_OUT_OF_MEMORY; @@ -571,7 +567,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, failf(data, "schannel: certificate format compatibility error " " for %s", blob ? "(memory blob)" : data->set.ssl.primary.clientcert); - free(cert_store_path); + curlx_free(cert_store_path); curlx_unicodefree(cert_path); if(fInCert) curlx_fclose(fInCert); @@ -589,7 +585,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, int cert_find_flags; const char *cert_showfilename_error = blob ? "(memory blob)" : data->set.ssl.primary.clientcert; - free(cert_store_path); + curlx_free(cert_store_path); curlx_unicodefree(cert_path); if(fInCert) { long cert_tell = 0; @@ -603,7 +599,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(continue_reading) continue_reading = fseek(fInCert, 0, SEEK_SET) == 0; if(continue_reading) - certdata = malloc(certsize + 1); + certdata = curlx_malloc(certsize + 1); if((!certdata) || ((int) fread(certdata, certsize, 1, fInCert) != 1)) continue_reading = FALSE; @@ -611,7 +607,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(!continue_reading) { failf(data, "schannel: Failed to read cert file %s", data->set.ssl.primary.clientcert); - free(certdata); + curlx_free(certdata); return CURLE_SSL_CERTPROBLEM; } } @@ -622,7 +618,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, if(data->set.ssl.key_passwd) pwd_len = strlen(data->set.ssl.key_passwd); - pszPassword = (WCHAR*)malloc(sizeof(WCHAR)*(pwd_len + 1)); + pszPassword = (WCHAR*)curlx_malloc(sizeof(WCHAR)*(pwd_len + 1)); if(pszPassword) { if(pwd_len > 0) str_w_len = MultiByteToWideChar(CP_UTF8, @@ -642,10 +638,10 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, else cert_store = PFXImportCertStore(&datablob, pszPassword, 0); - free(pszPassword); + curlx_free(pszPassword); } if(!blob) - free(certdata); + curlx_free(certdata); if(!cert_store) { DWORD errorcode = GetLastError(); if(errorcode == ERROR_INVALID_PASSWORD) @@ -699,12 +695,12 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, cert_store_name, (path_utf8 ? path_utf8 : "(unknown)"), GetLastError()); - free(cert_store_path); + curlx_free(cert_store_path); curlx_unicodefree(path_utf8); curlx_unicodefree(cert_path); return CURLE_SSL_CERTPROBLEM; } - free(cert_store_path); + curlx_free(cert_store_path); cert_thumbprint.pbData = cert_thumbprint_data; cert_thumbprint.cbData = CERT_THUMBPRINT_DATA_LEN; @@ -738,7 +734,7 @@ schannel_acquire_credential_handle(struct Curl_cfilter *cf, /* allocate memory for the reusable credential handle */ backend->cred = (struct Curl_schannel_cred *) - calloc(1, sizeof(struct Curl_schannel_cred)); + curlx_calloc(1, sizeof(struct Curl_schannel_cred)); if(!backend->cred) { failf(data, "schannel: unable to allocate memory"); @@ -1019,7 +1015,7 @@ schannel_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data) /* allocate memory for the security context handle */ backend->ctxt = (struct Curl_schannel_ctxt *) - calloc(1, sizeof(struct Curl_schannel_ctxt)); + curlx_calloc(1, sizeof(struct Curl_schannel_ctxt)); if(!backend->ctxt) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1170,7 +1166,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(!backend->decdata_buffer) { backend->decdata_offset = 0; backend->decdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE; - backend->decdata_buffer = malloc(backend->decdata_length); + backend->decdata_buffer = curlx_malloc(backend->decdata_length); if(!backend->decdata_buffer) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1182,7 +1178,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) backend->encdata_is_incomplete = FALSE; backend->encdata_offset = 0; backend->encdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE; - backend->encdata_buffer = malloc(backend->encdata_length); + backend->encdata_buffer = curlx_malloc(backend->encdata_length); if(!backend->encdata_buffer) { failf(data, "schannel: unable to allocate memory"); return CURLE_OUT_OF_MEMORY; @@ -1195,8 +1191,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) /* increase internal encrypted data buffer */ size_t reallocated_length = backend->encdata_offset + CURL_SCHANNEL_BUFFER_FREE_SIZE; - reallocated_buffer = realloc(backend->encdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->encdata_buffer, + reallocated_length); if(!reallocated_buffer) { failf(data, "schannel: unable to re-allocate memory"); @@ -1247,7 +1243,8 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) backend->encdata_offset, backend->encdata_length)); /* setup input buffers */ - InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, malloc(backend->encdata_offset), + InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, + curlx_malloc(backend->encdata_offset), curlx_uztoul(backend->encdata_offset)); InitSecBuffer(&inbuf[1], SECBUFFER_EMPTY, NULL, 0); InitSecBufferDesc(&inbuf_desc, inbuf, 2); @@ -1274,7 +1271,7 @@ schannel_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) if(!SOCKET_WRITABLE(Curl_conn_cf_get_socket(cf, data), 0)) { SCH_DEV(infof(data, "schannel: handshake waiting for writeable socket")); connssl->io_need = CURL_SSL_IO_NEED_SEND; - free(inbuf[0].pvBuffer); + curlx_free(inbuf[0].pvBuffer); return CURLE_OK; } @@ -1931,7 +1928,7 @@ schannel_send(struct Curl_cfilter *cf, struct Curl_easy *data, /* calculate the complete message length and allocate a buffer for it */ data_len = backend->stream_sizes.cbHeader + len + backend->stream_sizes.cbTrailer; - ptr = (unsigned char *)malloc(data_len); + ptr = (unsigned char *)curlx_malloc(data_len); if(!ptr) { return CURLE_OUT_OF_MEMORY; } @@ -2110,8 +2107,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(reallocated_length < min_encdata_length) { reallocated_length = min_encdata_length; } - reallocated_buffer = realloc(backend->encdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->encdata_buffer, + reallocated_length); if(!reallocated_buffer) { result = CURLE_OUT_OF_MEMORY; failf(data, "schannel: unable to re-allocate memory"); @@ -2196,8 +2193,8 @@ schannel_recv(struct Curl_cfilter *cf, struct Curl_easy *data, if(reallocated_length < len) { reallocated_length = len; } - reallocated_buffer = realloc(backend->decdata_buffer, - reallocated_length); + reallocated_buffer = curlx_realloc(backend->decdata_buffer, + reallocated_length); if(!reallocated_buffer) { result = CURLE_OUT_OF_MEMORY; failf(data, "schannel: unable to re-allocate memory"); @@ -2819,8 +2816,8 @@ static void schannel_cert_share_free(void *key, size_t key_len, void *p) if(share->cert_store) { CertCloseStore(share->cert_store, 0); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, @@ -2844,7 +2841,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) { return FALSE; } @@ -2852,7 +2849,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY)-1, share, schannel_cert_share_free)) { - free(share); + curlx_free(share); return FALSE; } } @@ -2866,7 +2863,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, } else { if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { return FALSE; } @@ -2877,7 +2874,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, if(share->cert_store) { CertCloseStore(share->cert_store, 0); } - free(share->CAfile); + curlx_free(share->CAfile); share->time = curlx_now(); share->cert_store = cert_store; diff --git a/lib/vtls/schannel_verify.c b/lib/vtls/schannel_verify.c index 72c42ed353..4ff7b5d536 100644 --- a/lib/vtls/schannel_verify.c +++ b/lib/vtls/schannel_verify.c @@ -49,10 +49,6 @@ #include "hostcheck.h" #include "../curlx/version_win32.h" -/* The last #include file should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define BACKEND ((struct schannel_ssl_backend_data *)connssl->backend) #define MAX_CAFILE_SIZE 1048576 /* 1 MiB */ @@ -319,7 +315,7 @@ static CURLcode add_certs_file_to_store(HCERTSTORE trust_store, } ca_file_bufsize = (size_t)file_size.QuadPart; - ca_file_buffer = (char *)malloc(ca_file_bufsize + 1); + ca_file_buffer = (char *)curlx_malloc(ca_file_bufsize + 1); if(!ca_file_buffer) { result = CURLE_OUT_OF_MEMORY; goto cleanup; @@ -606,7 +602,7 @@ CURLcode Curl_verify_host(struct Curl_cfilter *cf, /* CertGetNameString guarantees that the returned name will not contain * embedded null bytes. This appears to be undocumented behavior. */ - cert_hostname_buff = (LPTSTR)malloc(len * sizeof(TCHAR)); + cert_hostname_buff = (LPTSTR)curlx_malloc(len * sizeof(TCHAR)); if(!cert_hostname_buff) { result = CURLE_OUT_OF_MEMORY; goto cleanup; diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 3b242fd485..6eb60e41cf 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -81,15 +81,11 @@ #include #endif -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #define CLONE_STRING(var) \ do { \ if(source->var) { \ - dest->var = strdup(source->var); \ + dest->var = curlx_strdup(source->var); \ if(!dest->var) \ return FALSE; \ } \ @@ -111,7 +107,7 @@ static CURLcode blobdup(struct curl_blob **dest, if(src) { /* only if there is data to dupe! */ struct curl_blob *d; - d = malloc(sizeof(struct curl_blob) + src->len); + d = curlx_malloc(sizeof(struct curl_blob) + src->len); if(!d) return CURLE_OUT_OF_MEMORY; d->len = src->len; @@ -503,16 +499,16 @@ static struct ssl_connect_data *cf_ctx_new(struct Curl_easy *data, struct ssl_connect_data *ctx; (void)data; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) return NULL; ctx->ssl_impl = Curl_ssl; ctx->alpn = alpn; Curl_bufq_init2(&ctx->earlydata, CURL_SSL_EARLY_MAX, 1, BUFQ_OPT_NO_SPARES); - ctx->backend = calloc(1, ctx->ssl_impl->sizeof_ssl_backend_data); + ctx->backend = curlx_calloc(1, ctx->ssl_impl->sizeof_ssl_backend_data); if(!ctx->backend) { - free(ctx); + curlx_free(ctx); return NULL; } return ctx; @@ -523,8 +519,8 @@ static void cf_ctx_free(struct ssl_connect_data *ctx) if(ctx) { Curl_safefree(ctx->negotiated.alpn); Curl_bufq_free(&ctx->earlydata); - free(ctx->backend); - free(ctx); + curlx_free(ctx->backend); + curlx_free(ctx); } } @@ -617,7 +613,7 @@ void Curl_ssl_free_certinfo(struct Curl_easy *data) ci->certinfo[i] = NULL; } - free(ci->certinfo); /* free the actual array too */ + curlx_free(ci->certinfo); /* free the actual array too */ ci->certinfo = NULL; ci->num_of_certs = 0; } @@ -632,7 +628,7 @@ CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num) Curl_ssl_free_certinfo(data); /* Allocate the required certificate information structures */ - table = calloc((size_t) num, sizeof(struct curl_slist *)); + table = curlx_calloc((size_t) num, sizeof(struct curl_slist *)); if(!table) return CURLE_OUT_OF_MEMORY; @@ -783,7 +779,7 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, } /* compute sha256sum of public key */ - sha256sumdigest = malloc(CURL_SHA256_DIGEST_LENGTH); + sha256sumdigest = curlx_malloc(CURL_SHA256_DIGEST_LENGTH); if(!sha256sumdigest) return CURLE_OUT_OF_MEMORY; encode = Curl_ssl->sha256sum(pubkey, pubkeylen, @@ -1118,7 +1114,7 @@ static int multissl_setup(const struct Curl_ssl *backend) for(i = 0; available_backends[i]; i++) { if(curl_strequal(env, available_backends[i]->info.name)) { Curl_ssl = available_backends[i]; - free(env); + curlx_free(env); return 0; } } @@ -1129,7 +1125,7 @@ static int multissl_setup(const struct Curl_ssl *backend) if(curl_strequal(CURL_DEFAULT_SSL_BACKEND, available_backends[i]->info.name)) { Curl_ssl = available_backends[i]; - free(env); + curlx_free(env); return 0; } } @@ -1137,7 +1133,7 @@ static int multissl_setup(const struct Curl_ssl *backend) /* Fall back to first available backend */ Curl_ssl = available_backends[0]; - free(env); + curlx_free(env); return 0; } @@ -1190,7 +1186,7 @@ void Curl_ssl_peer_cleanup(struct ssl_peer *peer) { Curl_safefree(peer->sni); if(peer->dispname != peer->hostname) - free(peer->dispname); + curlx_free(peer->dispname); peer->dispname = NULL; Curl_safefree(peer->hostname); Curl_safefree(peer->scache_key); @@ -1266,13 +1262,13 @@ CURLcode Curl_ssl_peer_init(struct ssl_peer *peer, goto out; } - peer->hostname = strdup(ehostname); + peer->hostname = curlx_strdup(ehostname); if(!peer->hostname) goto out; if(!edispname || !strcmp(ehostname, edispname)) peer->dispname = peer->hostname; else { - peer->dispname = strdup(edispname); + peer->dispname = curlx_strdup(edispname); if(!peer->dispname) goto out; } @@ -1284,7 +1280,7 @@ CURLcode Curl_ssl_peer_init(struct ssl_peer *peer, if(len && (peer->hostname[len-1] == '.')) len--; if(len < USHRT_MAX) { - peer->sni = calloc(1, len + 1); + peer->sni = curlx_calloc(1, len + 1); if(!peer->sni) goto out; Curl_strntolower(peer->sni, peer->hostname, len); diff --git a/lib/vtls/vtls_scache.c b/lib/vtls/vtls_scache.c index 3524a25a44..21dfe2eaa0 100644 --- a/lib/vtls/vtls_scache.c +++ b/lib/vtls/vtls_scache.c @@ -47,10 +47,6 @@ #include "../rand.h" #include "../curlx/warnless.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - static bool cf_ssl_peer_key_is_global(const char *peer_key); @@ -104,10 +100,10 @@ static void cf_ssl_scache_session_ldestroy(void *udata, void *obj) { struct Curl_ssl_session *s = obj; (void)udata; - free(CURL_UNCONST(s->sdata)); - free(CURL_UNCONST(s->quic_tp)); - free((void *)s->alpn); - free(s); + curlx_free(CURL_UNCONST(s->sdata)); + curlx_free(CURL_UNCONST(s->quic_tp)); + curlx_free((void *)s->alpn); + curlx_free(s); } CURLcode @@ -131,15 +127,15 @@ Curl_ssl_session_create2(void *sdata, size_t sdata_len, struct Curl_ssl_session *s; if(!sdata || !sdata_len) { - free(sdata); + curlx_free(sdata); return CURLE_BAD_FUNCTION_ARGUMENT; } *psession = NULL; - s = calloc(1, sizeof(*s)); + s = curlx_calloc(1, sizeof(*s)); if(!s) { - free(sdata); - free(quic_tp); + curlx_free(sdata); + curlx_free(quic_tp); return CURLE_OUT_OF_MEMORY; } @@ -151,7 +147,7 @@ Curl_ssl_session_create2(void *sdata, size_t sdata_len, s->quic_tp = quic_tp; s->quic_tp_len = quic_tp_len; if(alpn) { - s->alpn = strdup(alpn); + s->alpn = curlx_strdup(alpn); if(!s->alpn) { cf_ssl_scache_session_ldestroy(NULL, s); return CURLE_OUT_OF_MEMORY; @@ -231,7 +227,7 @@ cf_ssl_scache_peer_init(struct Curl_ssl_scache_peer *peer, DEBUGASSERT(!peer->ssl_peer_key); if(ssl_peer_key) { - peer->ssl_peer_key = strdup(ssl_peer_key); + peer->ssl_peer_key = curlx_strdup(ssl_peer_key); if(!peer->ssl_peer_key) goto out; peer->hmac_set = FALSE; @@ -246,17 +242,17 @@ cf_ssl_scache_peer_init(struct Curl_ssl_scache_peer *peer, goto out; } if(clientcert) { - peer->clientcert = strdup(clientcert); + peer->clientcert = curlx_strdup(clientcert); if(!peer->clientcert) goto out; } if(srp_username) { - peer->srp_username = strdup(srp_username); + peer->srp_username = curlx_strdup(srp_username); if(!peer->srp_username) goto out; } if(srp_password) { - peer->srp_password = strdup(srp_password); + peer->srp_password = curlx_strdup(srp_password); if(!peer->srp_password) goto out; } @@ -315,13 +311,13 @@ CURLcode Curl_ssl_scache_create(size_t max_peers, size_t i; *pscache = NULL; - peers = calloc(max_peers, sizeof(*peers)); + peers = curlx_calloc(max_peers, sizeof(*peers)); if(!peers) return CURLE_OUT_OF_MEMORY; - scache = calloc(1, sizeof(*scache)); + scache = curlx_calloc(1, sizeof(*scache)); if(!scache) { - free(peers); + curlx_free(peers); return CURLE_OUT_OF_MEMORY; } @@ -348,8 +344,8 @@ void Curl_ssl_scache_destroy(struct Curl_ssl_scache *scache) for(i = 0; i < scache->peer_count; ++i) { cf_ssl_scache_clear_peer(&scache->peers[i]); } - free(scache->peers); - free(scache); + curlx_free(scache->peers); + curlx_free(scache); } } @@ -396,7 +392,8 @@ static CURLcode cf_ssl_peer_key_add_path(struct dynbuf *buf, char *abspath = realpath(path, NULL); if(abspath) { CURLcode r = curlx_dyn_addf(buf, ":%s-%s", name, abspath); - (free)(abspath); /* allocated by libc, free without memdebug */ + /* !checksrc! disable BANNEDFUNC 1 */ + free(abspath); /* allocated by libc, free without memdebug */ return r; } *is_local = TRUE; @@ -675,7 +672,7 @@ cf_ssl_find_peer_by_key(struct Curl_easy *data, /* remember peer_key for future lookups */ CURL_TRC_SSLS(data, "peer entry %zu key recovered: %s", i, ssl_peer_key); - scache->peers[i].ssl_peer_key = strdup(ssl_peer_key); + scache->peers[i].ssl_peer_key = curlx_strdup(ssl_peer_key); if(!scache->peers[i].ssl_peer_key) { result = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vtls/vtls_spack.c b/lib/vtls/vtls_spack.c index d86f31d727..070bb485a3 100644 --- a/lib/vtls/vtls_spack.c +++ b/lib/vtls/vtls_spack.c @@ -32,10 +32,6 @@ #include "vtls_spack.h" #include "../strdup.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifndef UINT16_MAX #define UINT16_MAX 0xffff #endif @@ -267,7 +263,7 @@ CURLcode Curl_ssl_session_unpack(struct Curl_easy *data, goto out; } - s = calloc(1, sizeof(*s)); + s = curlx_calloc(1, sizeof(*s)); if(!s) { r = CURLE_OUT_OF_MEMORY; goto out; diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index 2ad033f988..eae17078fd 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -75,10 +75,6 @@ #include #include "wolfssl.h" -/* The last #include files should be: */ -#include "../curl_memory.h" -#include "../memdebug.h" - #ifdef HAVE_WOLFSSL_CTX_GENERATEECHCONFIG #define USE_ECH_WOLFSSL #endif @@ -447,7 +443,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, result = CURLE_FAILED_INIT; goto out; } - sdata = calloc(1, sdata_len); + sdata = curlx_calloc(1, sdata_len); if(!sdata) { failf(data, "unable to allocate session buffer of %u bytes", sdata_len); result = CURLE_OUT_OF_MEMORY; @@ -462,7 +458,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, if(quic_tp && quic_tp_len) { qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len); if(!qtp_clone) { - free(sdata); + curlx_free(sdata); return CURLE_OUT_OF_MEMORY; } } @@ -483,7 +479,7 @@ CURLcode Curl_wssl_cache_session(struct Curl_cfilter *cf, } out: - free(sdata); + curlx_free(sdata); return result; } @@ -726,8 +722,8 @@ static void wssl_x509_share_free(void *key, size_t key_len, void *p) if(share->store) { wolfSSL_X509_STORE_free(share->store); } - free(share->CAfile); - free(share); + curlx_free(share->CAfile); + curlx_free(share); } static bool @@ -792,14 +788,14 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, sizeof(MPROTO_WSSL_X509_KEY)-1); if(!share) { - share = calloc(1, sizeof(*share)); + share = curlx_calloc(1, sizeof(*share)); if(!share) return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), sizeof(MPROTO_WSSL_X509_KEY)-1, share, wssl_x509_share_free)) { - free(share); + curlx_free(share); return; } } @@ -808,7 +804,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, char *CAfile = NULL; if(conn_config->CAfile) { - CAfile = strdup(conn_config->CAfile); + CAfile = curlx_strdup(conn_config->CAfile); if(!CAfile) { wolfSSL_X509_STORE_free(store); return; @@ -817,7 +813,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, if(share->store) { wolfSSL_X509_STORE_free(share->store); - free(share->CAfile); + curlx_free(share->CAfile); } share->time = curlx_now(); @@ -1821,7 +1817,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf, &b64str, &blen); if(!result && b64str) infof(data, "ECH: (not yet) retry_configs %s", b64str); - free(b64str); + curlx_free(b64str); } return CURLE_SSL_CONNECT_ERROR; } diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c index 417a5382d8..fcc0d0e1da 100644 --- a/lib/vtls/x509asn1.c +++ b/lib/vtls/x509asn1.c @@ -49,10 +49,6 @@ #include "x509asn1.h" #include "../curlx/dynbuf.h" -/* The last 2 #include files should be in this order */ -#include "../curl_memory.h" -#include "../memdebug.h" - /* * Constants. */ @@ -1260,7 +1256,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, if(!result) result = curlx_dyn_add(&out, "-----END CERTIFICATE-----\n"); } - free(certptr); + curlx_free(certptr); if(!result) if(data->set.ssl.certinfo) result = ssl_push_certinfo_dyn(data, certnum, "Cert", &out); diff --git a/lib/ws.c b/lib/ws.c index 15dc2e9aea..93e13e1ac1 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -43,10 +43,6 @@ #include "curlx/strparse.h" #include "curlx/warnless.h" -/* The last 2 #include files should be in this order */ -#include "curl_memory.h" -#include "memdebug.h" - /*** RFC 6455 Section 5.2 @@ -1281,11 +1277,11 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req) return result; DEBUGASSERT(randlen < sizeof(keyval)); if(randlen >= sizeof(keyval)) { - free(randstr); + curlx_free(randstr); return CURLE_FAILED_INIT; } strcpy(keyval, randstr); - free(randstr); + curlx_free(randstr); for(i = 0; !result && (i < CURL_ARRAYSIZE(heads)); i++) { if(!Curl_checkheaders(data, heads[i].name, strlen(heads[i].name))) { result = curlx_dyn_addf(req, "%s: %s\r\n", heads[i].name, @@ -1305,7 +1301,7 @@ static void ws_conn_dtor(void *key, size_t klen, void *entry) (void)klen; Curl_bufq_free(&ws->recvbuf); Curl_bufq_free(&ws->sendbuf); - free(ws); + curlx_free(ws); } /* @@ -1325,7 +1321,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, ws = Curl_conn_meta_get(data->conn, CURL_META_PROTO_WS_CONN); if(!ws) { size_t chunk_size = WS_CHUNK_SIZE; - ws = calloc(1, sizeof(*ws)); + ws = curlx_calloc(1, sizeof(*ws)); if(!ws) return CURLE_OUT_OF_MEMORY; #ifdef DEBUGBUILD diff --git a/packages/Makefile.am b/packages/Makefile.am index 43e544a019..8b6d4dc4b2 100644 --- a/packages/Makefile.am +++ b/packages/Makefile.am @@ -24,6 +24,7 @@ SUBDIRS = vms EXTRA_DIST = README.md \ + OS400/.checksrc \ OS400/README.OS400 \ OS400/rpg-examples \ OS400/ccsidcurl.c \ diff --git a/packages/OS400/.checksrc b/packages/OS400/.checksrc new file mode 100644 index 0000000000..aae405506b --- /dev/null +++ b/packages/OS400/.checksrc @@ -0,0 +1,9 @@ +# Copyright (C) Daniel Stenberg, , et al. +# +# SPDX-License-Identifier: curl + +# Possible not what we want, but cannot test, just silence the warnings +allowfunc calloc +allowfunc free +allowfunc malloc +allowfunc realloc diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index 49290ff137..87b72af963 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -69,10 +69,12 @@ my %banfunc = ( "aprintf" => 1, "atoi" => 1, "atol" => 1, + "calloc" => 1, "fclose" => 1, "fdopen" => 1, "fopen" => 1, "fprintf" => 1, + "free" => 1, "freeaddrinfo" => 1, "freopen" => 1, "getaddrinfo" => 1, @@ -85,11 +87,13 @@ my %banfunc = ( "LoadLibraryExW" => 1, "LoadLibraryW" => 1, "localtime" => 1, + "malloc" => 1, "mbstowcs" => 1, "msnprintf" => 1, "mvsnprintf" => 1, "open" => 1, "printf" => 1, + "realloc" => 1, "recv" => 1, "send" => 1, "snprintf" => 1, @@ -99,6 +103,7 @@ my %banfunc = ( "sscanf" => 1, "stat" => 1, "strcat" => 1, + "strdup" => 1, "strerror" => 1, "strncat" => 1, "strncpy" => 1, diff --git a/src/mkhelp.pl b/src/mkhelp.pl index d1a040c0cc..b3a6c5abdc 100755 --- a/src/mkhelp.pl +++ b/src/mkhelp.pl @@ -78,7 +78,6 @@ if($c) print < -#include /* keep this as LAST include */ static const unsigned char hugehelpgz[] = { /* This mumbo-jumbo is the huge help text compressed with gzip. Thanks to this operation, the size of this data shrank from $gzip @@ -105,13 +104,13 @@ HEAD static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size) { (void)opaque; - /* not a typo, keep it calloc() */ - return (voidpf) calloc(items, size); + /* not a typo, keep it curlx_calloc() */ + return (voidpf)curlx_calloc(items, size); } static void zfree_func(voidpf opaque, voidpf ptr) { (void)opaque; - free(ptr); + curlx_free(ptr); } #define HEADERLEN 10 @@ -136,7 +135,7 @@ void hugehelp(void) if(inflateInit2(&z, -MAX_WBITS) != Z_OK) return; - buf = malloc(BUF_SIZE); + buf = curlx_malloc(BUF_SIZE); if(buf) { while(1) { z.avail_out = BUF_SIZE; @@ -150,7 +149,7 @@ void hugehelp(void) else break; /* error */ } - free(buf); + curlx_free(buf); } inflateEnd(&z); } @@ -176,7 +175,7 @@ void showhelp(const char *trigger, const char *arg, const char *endarg) if(inflateInit2(&z, -MAX_WBITS) != Z_OK) return; - buf = malloc(BUF_SIZE); + buf = curlx_malloc(BUF_SIZE); if(buf) { while(1) { z.avail_out = BUF_SIZE; @@ -192,7 +191,7 @@ void showhelp(const char *trigger, const char *arg, const char *endarg) else break; /* error */ } - free(buf); + curlx_free(buf); } inflateEnd(&z); } diff --git a/src/slist_wc.c b/src/slist_wc.c index 7f1e8f19be..26a91362b8 100644 --- a/src/slist_wc.c +++ b/src/slist_wc.c @@ -28,9 +28,6 @@ #include "slist_wc.h" -/* The last #include files should be: */ -#include "memdebug.h" - /* * slist_wc_append() appends a string to the linked list. This function can be * used as an initialization function as well as an append function. @@ -44,7 +41,7 @@ struct slist_wc *slist_wc_append(struct slist_wc *list, return NULL; if(!list) { - list = malloc(sizeof(struct slist_wc)); + list = curlx_malloc(sizeof(struct slist_wc)); if(!list) { curl_slist_free_all(new_item); @@ -68,7 +65,7 @@ void slist_wc_free_all(struct slist_wc *list) return; curl_slist_free_all(list->first); - free(list); + curlx_free(list); } #endif /* CURL_DISABLE_LIBCURL_OPTION */ diff --git a/src/terminal.c b/src/terminal.c index 867ca6edcf..bb3e2ac611 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -28,7 +28,6 @@ #endif #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ #ifdef HAVE_TERMIOS_H # include diff --git a/src/tool_bname.c b/src/tool_bname.c index 4ba1a3b8ee..50d77abb96 100644 --- a/src/tool_bname.c +++ b/src/tool_bname.c @@ -25,8 +25,6 @@ #include "tool_bname.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifndef HAVE_BASENAME char *tool_basename(char *path) diff --git a/src/tool_cb_dbg.c b/src/tool_cb_dbg.c index 043daef26d..b858b6688e 100644 --- a/src/tool_cb_dbg.c +++ b/src/tool_cb_dbg.c @@ -28,8 +28,6 @@ #include "tool_cb_dbg.h" #include "tool_util.h" -#include "memdebug.h" /* keep this as LAST include */ - static void dump(const char *timebuf, const char *idsbuf, const char *text, FILE *stream, const unsigned char *ptr, size_t size, trace tracetype, curl_infotype infotype); diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c index d4431a74b9..7a5a475981 100644 --- a/src/tool_cb_hdr.c +++ b/src/tool_cb_hdr.c @@ -36,8 +36,6 @@ #include "tool_libinfo.h" #include "tool_strdup.h" -#include "memdebug.h" /* keep this as LAST include */ - static char *parse_filename(const char *ptr, size_t len); #ifdef _WIN32 @@ -212,14 +210,14 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) if(filename) { if(outs->stream) { /* indication of problem, get out! */ - free(filename); + curlx_free(filename); return CURL_WRITEFUNC_ERROR; } if(per->config->output_dir) { outs->filename = curl_maprintf("%s/%s", per->config->output_dir, filename); - free(filename); + curlx_free(filename); if(!outs->filename) return CURL_WRITEFUNC_ERROR; } @@ -252,7 +250,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) if(clone) { struct curl_slist *old = hdrcbdata->headlist; hdrcbdata->headlist = curl_slist_append(old, clone); - free(clone); + curlx_free(clone); if(!hdrcbdata->headlist) { curl_slist_free_all(old); return CURL_WRITEFUNC_ERROR; @@ -479,7 +477,7 @@ locdone: curl_free(finalurl); curl_free(scheme); curl_url_cleanup(u); - free(copyloc); + curlx_free(copyloc); } } #endif diff --git a/src/tool_cb_prg.c b/src/tool_cb_prg.c index 5f33c7c29c..6ae53b3ba2 100644 --- a/src/tool_cb_prg.c +++ b/src/tool_cb_prg.c @@ -29,8 +29,6 @@ #include "tool_operate.h" #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ - #define MAX_BARLENGTH 400 #define MIN_BARLENGTH 20 diff --git a/src/tool_cb_rea.c b/src/tool_cb_rea.c index cc7ef5a550..0f2bf81771 100644 --- a/src/tool_cb_rea.c +++ b/src/tool_cb_rea.c @@ -38,8 +38,6 @@ #include "tool_util.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifndef _WIN32 /* Wait up to a number of milliseconds for socket activity. This function waits on read activity on a file descriptor that is not a socket which diff --git a/src/tool_cb_see.c b/src/tool_cb_see.c index fd1b4c563c..ea5c8e313b 100644 --- a/src/tool_cb_see.c +++ b/src/tool_cb_see.c @@ -27,8 +27,6 @@ #include "tool_operate.h" #include "tool_cb_see.h" -#include "memdebug.h" /* keep this as LAST include */ - /* ** callback for CURLOPT_SEEKFUNCTION ** diff --git a/src/tool_cb_wrt.c b/src/tool_cb_wrt.c index 48f5fea3c9..5696df2a59 100644 --- a/src/tool_cb_wrt.c +++ b/src/tool_cb_wrt.c @@ -28,8 +28,6 @@ #include "tool_cb_wrt.h" #include "tool_operate.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef _WIN32 #define OPENMODE S_IREAD | S_IWRITE #else @@ -211,8 +209,8 @@ static size_t win_console(intptr_t fhnd, struct OutStruct *outs, /* grow the buffer if needed */ if(len > global->term.len) { - wchar_t *buf = (wchar_t *) realloc(global->term.buf, - len * sizeof(wchar_t)); + wchar_t *buf = (wchar_t *)curlx_realloc(global->term.buf, + len * sizeof(wchar_t)); if(!buf) return CURL_WRITEFUNC_ERROR; global->term.len = len; diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c index 086e4ac216..ab4892b065 100644 --- a/src/tool_cfgable.c +++ b/src/tool_cfgable.c @@ -28,7 +28,6 @@ #include "tool_paramhlp.h" #include "tool_main.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ static struct GlobalConfig globalconf; struct GlobalConfig *global; @@ -36,7 +35,7 @@ struct GlobalConfig *global; struct OperationConfig *config_alloc(void) { struct OperationConfig *config = - calloc(1, sizeof(struct OperationConfig)); + curlx_calloc(1, sizeof(struct OperationConfig)); if(!config) return NULL; @@ -199,7 +198,7 @@ void config_free(struct OperationConfig *config) struct OperationConfig *prev = last->prev; free_config_fields(last); - free(last); + curlx_free(last); last = prev; } @@ -236,12 +235,12 @@ CURLcode globalconf_init(void) if(result) { errorf("error retrieving curl library information"); - free(global->first); + curlx_free(global->first); } } else { errorf("error initializing curl library"); - free(global->first); + curlx_free(global->first); } } else { @@ -263,7 +262,7 @@ static void free_globalconfig(void) tool_safefree(global->ssl_sessions); tool_safefree(global->libcurl); #ifdef _WIN32 - free(global->term.buf); + curlx_free(global->term.buf); #endif } diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index dc78f2db44..0eac0185f2 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -42,7 +42,7 @@ #define checkprefix(a,b) curl_strnequal(b, STRCONST(a)) #define tool_safefree(ptr) \ - do { free((ptr)); (ptr) = NULL;} while(0) + do { curlx_free((ptr)); (ptr) = NULL;} while(0) extern struct GlobalConfig *global; diff --git a/src/tool_dirhie.c b/src/tool_dirhie.c index 17b2d01e9b..31962bd1c5 100644 --- a/src/tool_dirhie.c +++ b/src/tool_dirhie.c @@ -30,8 +30,6 @@ #include "tool_dirhie.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - #if defined(_WIN32) || (defined(MSDOS) && !defined(__DJGPP__)) # define mkdir(x,y) (mkdir)((x)) # ifndef F_OK diff --git a/src/tool_doswin.c b/src/tool_doswin.c index cd0ec3b9c1..ee236178c2 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -40,8 +40,6 @@ #include "tool_doswin.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef _WIN32 # undef PATH_MAX # define PATH_MAX MAX_PATH @@ -133,7 +131,7 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name, if(len > max_sanitized_len) return SANITIZE_ERR_INVALID_PATH; - target = strdup(file_name); + target = curlx_strdup(file_name); if(!target) return SANITIZE_ERR_OUT_OF_MEMORY; @@ -183,28 +181,28 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name, #ifdef MSDOS sc = msdosify(&p, target, flags); - free(target); + curlx_free(target); if(sc) return sc; target = p; len = strlen(target); if(len > max_sanitized_len) { - free(target); + curlx_free(target); return SANITIZE_ERR_INVALID_PATH; } #endif if(!(flags & SANITIZE_ALLOW_RESERVED)) { sc = rename_if_reserved_dos(&p, target, flags); - free(target); + curlx_free(target); if(sc) return sc; target = p; len = strlen(target); if(len > max_sanitized_len) { - free(target); + curlx_free(target); return SANITIZE_ERR_INVALID_PATH; } } @@ -415,7 +413,7 @@ static SANITIZEcode msdosify(char **const sanitized, const char *file_name, return SANITIZE_ERR_INVALID_PATH; } - *sanitized = strdup(dos_name); + *sanitized = curlx_strdup(dos_name); return *sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY; } #endif /* MSDOS */ @@ -457,7 +455,7 @@ static SANITIZEcode rename_if_reserved_dos(char **const sanitized, #ifndef MSDOS if((flags & SANITIZE_ALLOW_PATH) && file_name[0] == '\\' && file_name[1] == '\\') { - *sanitized = strdup(file_name); + *sanitized = curlx_strdup(file_name); if(!*sanitized) return SANITIZE_ERR_OUT_OF_MEMORY; return SANITIZE_ERR_OK; @@ -544,7 +542,7 @@ static SANITIZEcode rename_if_reserved_dos(char **const sanitized, } #endif - *sanitized = strdup(fname); + *sanitized = curlx_strdup(fname); return *sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY; } @@ -597,7 +595,7 @@ CURLcode FindWin32CACert(struct OperationConfig *config, char *mstr = curlx_convert_tchar_to_UTF8(buf); tool_safefree(config->cacert); if(mstr) - config->cacert = strdup(mstr); + config->cacert = curlx_strdup(mstr); curlx_unicodefree(mstr); if(!config->cacert) result = CURLE_OUT_OF_MEMORY; @@ -801,7 +799,7 @@ ThreadCleanup: if(socket_w != CURL_SOCKET_BAD) sclose(socket_w); - free(tdata); + curlx_free(tdata); return 0; } @@ -824,9 +822,10 @@ curl_socket_t win32_stdin_read_thread(void) do { /* Prepare handles for thread */ - tdata = (struct win_thread_data*)calloc(1, sizeof(struct win_thread_data)); + tdata = (struct win_thread_data*) + curlx_calloc(1, sizeof(struct win_thread_data)); if(!tdata) { - errorf("calloc() error"); + errorf("curlx_calloc() error"); break; } /* Create the listening socket for the thread. When it starts, it will @@ -937,7 +936,7 @@ curl_socket_t win32_stdin_read_thread(void) if(tdata->socket_l != CURL_SOCKET_BAD) sclose(tdata->socket_l); - free(tdata); + curlx_free(tdata); } return CURL_SOCKET_BAD; diff --git a/src/tool_easysrc.c b/src/tool_easysrc.c index 65d01d5f85..4747f6dfe6 100644 --- a/src/tool_easysrc.c +++ b/src/tool_easysrc.c @@ -31,8 +31,6 @@ #include "tool_easysrc.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - /* global variable definitions, for easy-interface source code generation */ struct slist_wc *easysrc_decl; /* Variable declarations */ diff --git a/src/tool_findfile.c b/src/tool_findfile.c index 6e9fbdfd60..4dbd7bccb4 100644 --- a/src/tool_findfile.c +++ b/src/tool_findfile.c @@ -36,8 +36,6 @@ #include "tool_findfile.h" #include "tool_cfgable.h" -#include "memdebug.h" /* keep this as LAST include */ - struct finder { const char *env; const char *append; @@ -75,7 +73,7 @@ static char *checkhome(const char *home, const char *fname, bool dotscore) if(c) { int fd = curlx_open(c, O_RDONLY); if(fd >= 0) { - char *path = strdup(c); + char *path = curlx_strdup(c); close(fd); curl_free(c); return path; diff --git a/src/tool_formparse.c b/src/tool_formparse.c index c1e9abe9d0..181abf7b86 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -30,13 +30,11 @@ #include "tool_formparse.h" #include "tool_parsecfg.h" -#include "memdebug.h" /* keep this as LAST include */ - /* tool_mime functions. */ static struct tool_mime *tool_mime_new(struct tool_mime *parent, toolmimekind kind) { - struct tool_mime *m = (struct tool_mime *) calloc(1, sizeof(*m)); + struct tool_mime *m = (struct tool_mime *)curlx_calloc(1, sizeof(*m)); if(m) { m->kind = kind; @@ -60,11 +58,11 @@ static struct tool_mime *tool_mime_new_data(struct tool_mime *parent, char *mime_data_copy; struct tool_mime *m = NULL; - mime_data_copy = strdup(mime_data); + mime_data_copy = curlx_strdup(mime_data); if(mime_data_copy) { m = tool_mime_new(parent, TOOLMIME_DATA); if(!m) - free(mime_data_copy); + curlx_free(mime_data_copy); else m->data = mime_data_copy; } @@ -107,11 +105,11 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent, *errcode = CURLE_OUT_OF_MEMORY; if(strcmp(filename, "-")) { /* This is a normal file. */ - char *filedup = strdup(filename); + char *filedup = curlx_strdup(filename); if(filedup) { m = tool_mime_new(parent, TOOLMIME_FILE); if(!m) - free(filedup); + curlx_free(filedup); else { m->data = filedup; if(!isremotefile) @@ -152,7 +150,7 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent, default: if(!stdinsize) { /* Zero-length data has been freed. Re-create it. */ - data = strdup(""); + data = curlx_strdup(""); if(!data) return m; } @@ -190,7 +188,7 @@ void tool_mime_free(struct tool_mime *mime) tool_safefree(mime->encoder); tool_safefree(mime->data); curl_slist_free_all(mime->headers); - free(mime); + curlx_free(mime); } } @@ -711,7 +709,7 @@ static int get_param_part(char endchar, #define SET_TOOL_MIME_PTR(m, field) \ do { \ if(field) { \ - (m)->field = strdup(field); \ + (m)->field = curlx_strdup(field); \ if(!(m)->field) \ goto fail; \ } \ @@ -745,7 +743,7 @@ int formparse(const char *input, } /* Make a copy we can overwrite. */ - contents = strdup(input); + contents = curlx_strdup(input); if(!contents) goto fail; diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 76113e45bd..7afb0c5fc0 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -38,22 +38,20 @@ #include "tool_help.h" #include "var.h" -#include "memdebug.h" /* keep this as LAST include */ - #define ALLOW_BLANK TRUE #define DENY_BLANK FALSE static ParameterError getstr(char **str, const char *val, bool allowblank) { if(*str) { - free(*str); + curlx_free(*str); *str = NULL; } DEBUGASSERT(val); if(!allowblank && !val[0]) return PARAM_BLANK_STRING; - *str = strdup(val); + *str = curlx_strdup(val); if(!*str) return PARAM_NO_MEM; @@ -64,14 +62,14 @@ static ParameterError getstrn(char **str, const char *val, size_t len, bool allowblank) { if(*str) { - free(*str); + curlx_free(*str); *str = NULL; } DEBUGASSERT(val); if(!allowblank && !val[0]) return PARAM_BLANK_STRING; - *str = malloc(len + 1); + *str = curlx_malloc(len + 1); if(!*str) return PARAM_NO_MEM; @@ -407,13 +405,13 @@ ParameterError parse_cert_parameter(const char *cert_parameter, * means no passphrase was given and no characters escaped */ if(curl_strnequal(cert_parameter, "pkcs11:", 7) || !strpbrk(cert_parameter, ":\\")) { - *certname = strdup(cert_parameter); + *certname = curlx_strdup(cert_parameter); if(!*certname) return PARAM_NO_MEM; return PARAM_OK; } /* deal with escaped chars; find unescaped colon if it exists */ - certname_place = malloc(param_length + 1); + certname_place = curlx_malloc(param_length + 1); if(!certname_place) { err = PARAM_NO_MEM; goto done; @@ -475,7 +473,7 @@ ParameterError parse_cert_parameter(const char *cert_parameter, * above; if we are still here, this is a separating colon */ param_place++; if(*param_place) { - *passphrase = strdup(param_place); + *passphrase = curlx_strdup(param_place); if(!*passphrase) err = PARAM_NO_MEM; } @@ -527,10 +525,10 @@ GetFileAndPassword(const char *nextarg, char **file, char **password) /* nextarg is never NULL here */ err = parse_cert_parameter(nextarg, &certname, &passphrase); if(!err) { - free(*file); + curlx_free(*file); *file = certname; if(passphrase) { - free(*password); + curlx_free(*password); *password = passphrase; } } @@ -668,7 +666,7 @@ static ParameterError data_urlencode(const char *nextarg, if(!postdata) { /* no data from the file, point to a zero byte string to make this get sent as a POST anyway */ - postdata = strdup(""); + postdata = curlx_strdup(""); if(!postdata) return PARAM_NO_MEM; size = 0; @@ -870,7 +868,7 @@ static ParameterError url_query(const char *nextarg, if(*nextarg == '+') { /* use without encoding */ - query = strdup(&nextarg[1]); + query = curlx_strdup(&nextarg[1]); if(!query) err = PARAM_NO_MEM; } @@ -880,11 +878,11 @@ static ParameterError url_query(const char *nextarg, if(!err) { if(config->query) { CURLcode result = curlx_dyn_addf(&dyn, "%s&%s", config->query, query); - free(query); + curlx_free(query); if(result) err = PARAM_NO_MEM; else { - free(config->query); + curlx_free(config->query); config->query = curlx_dyn_ptr(&dyn); } } @@ -944,7 +942,7 @@ static ParameterError set_data(cmdline_t cmd, if(!postdata) { /* no data from the file, point to a zero byte string to make this get sent as a POST anyway */ - postdata = strdup(""); + postdata = curlx_strdup(""); if(!postdata) return PARAM_NO_MEM; } @@ -1240,7 +1238,7 @@ static ParameterError parse_ech(struct OperationConfig *config, if(err) return err; config->ech_config = curl_maprintf("ecl:%s",tmpcfg); - free(tmpcfg); + curlx_free(tmpcfg); if(!config->ech_config) return PARAM_NO_MEM; } /* file done */ @@ -1424,8 +1422,8 @@ static ParameterError parse_range(struct OperationConfig *config, "Appending one for you"); curl_msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", value); - free(config->range); - config->range = strdup(buffer); + curlx_free(config->range); + config->range = curlx_strdup(buffer); if(!config->range) err = PARAM_NO_MEM; } @@ -1509,8 +1507,8 @@ static ParameterError parse_verbose(bool toggle) switch(global->verbosity) { case 0: global->verbosity = 1; - free(global->trace_dump); - global->trace_dump = strdup("%"); + curlx_free(global->trace_dump); + global->trace_dump = curlx_strdup("%"); if(!global->trace_dump) err = PARAM_NO_MEM; else { @@ -3021,7 +3019,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ error: if(nextalloc) - free(CURL_UNCONST(nextarg)); + curlx_free(CURL_UNCONST(nextarg)); return err; } diff --git a/src/tool_getpass.c b/src/tool_getpass.c index 014c22813a..b0316510bc 100644 --- a/src/tool_getpass.c +++ b/src/tool_getpass.c @@ -51,8 +51,6 @@ #endif #include "tool_getpass.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef __VMS /* VMS implementation */ char *getpass_r(const char *prompt, char *buffer, size_t buflen) diff --git a/src/tool_help.c b/src/tool_help.c index 4509fa2b94..bbe8dc68a4 100644 --- a/src/tool_help.c +++ b/src/tool_help.c @@ -33,8 +33,6 @@ #include "tool_cfgable.h" #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ - struct category_descriptors { const char *opt; const char *desc; @@ -364,7 +362,7 @@ void tool_version_info(void) #ifdef CURL_CA_EMBED ++feat_ext_count; #endif - feat_ext = malloc(sizeof(*feature_names) * (feat_ext_count + 1)); + feat_ext = curlx_malloc(sizeof(*feature_names) * (feat_ext_count + 1)); if(feat_ext) { memcpy((void *)feat_ext, feature_names, sizeof(*feature_names) * feature_count); @@ -379,7 +377,7 @@ void tool_version_info(void) for(builtin = feat_ext; *builtin; ++builtin) curl_mprintf(" %s", *builtin); puts(""); /* newline */ - free((void *)feat_ext); + curlx_free((void *)feat_ext); } } if(strcmp(CURL_VERSION, curlinfo->version)) { diff --git a/src/tool_helpers.c b/src/tool_helpers.c index b36bd4af1d..2e308a248f 100644 --- a/src/tool_helpers.c +++ b/src/tool_helpers.c @@ -27,7 +27,6 @@ #include "tool_msgs.h" #include "tool_getparam.h" #include "tool_helpers.h" -#include "memdebug.h" /* keep this as LAST include */ /* ** Helper functions that are used from more than one source file. diff --git a/src/tool_ipfs.c b/src/tool_ipfs.c index 0214a2004f..c1d27fc99b 100644 --- a/src/tool_ipfs.c +++ b/src/tool_ipfs.c @@ -28,7 +28,6 @@ #include "tool_cfgable.h" #include "tool_msgs.h" #include "tool_ipfs.h" -#include "memdebug.h" /* keep this as LAST include */ /* input string ends in slash? */ static bool has_trailing_slash(const char *input) @@ -45,7 +44,7 @@ static char *ipfs_gateway(void) char *gateway_env = getenv("IPFS_GATEWAY"); if(gateway_env) - return strdup(gateway_env); + return curlx_strdup(gateway_env); /* Try to find the gateway in the IPFS data folder. */ ipfs_path_c = curl_getenv("IPFS_PATH"); @@ -133,7 +132,7 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url, if(config->ipfs_gateway) { if(!curl_url_set(gatewayurl, CURLUPART_URL, config->ipfs_gateway, CURLU_GUESS_SCHEME)) { - gateway = strdup(config->ipfs_gateway); + gateway = curlx_strdup(config->ipfs_gateway); if(!gateway) { result = CURLE_URL_MALFORMAT; goto clean; @@ -200,8 +199,8 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url, if(curl_url_get(uh, CURLUPART_URL, &cloneurl, CURLU_URLENCODE)) { goto clean; } - /* we need to strdup the URL so that we can call free() on it later */ - *url = strdup(cloneurl); + /* we need to strdup the URL so that we can call curlx_free() on it later */ + *url = curlx_strdup(cloneurl); curl_free(cloneurl); if(!*url) goto clean; @@ -209,7 +208,7 @@ CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url, result = CURLE_OK; clean: - free(gateway); + curlx_free(gateway); curl_free(gwhost); curl_free(gwpath); curl_free(gwquery); diff --git a/src/tool_libinfo.c b/src/tool_libinfo.c index d755532652..1687005481 100644 --- a/src/tool_libinfo.c +++ b/src/tool_libinfo.c @@ -24,7 +24,6 @@ #include "tool_setup.h" #include "tool_libinfo.h" -#include "memdebug.h" /* keep this as LAST include */ /* global variable definitions, for libcurl runtime info */ diff --git a/src/tool_libinfo.h b/src/tool_libinfo.h index 5e6e1de24c..ddc41a1338 100644 --- a/src/tool_libinfo.h +++ b/src/tool_libinfo.h @@ -27,7 +27,6 @@ /* global variable declarations, for libcurl runtime info */ - extern curl_version_info_data *curlinfo; extern const char * const *built_in_protos; diff --git a/src/tool_main.c b/src/tool_main.c index 8047e663c8..eb15ae740d 100644 --- a/src/tool_main.c +++ b/src/tool_main.c @@ -42,13 +42,6 @@ #include "tool_libinfo.h" #include "tool_stderr.h" -/* - * This is low-level hard-hacking memory leak tracking and similar. Using - * the library level code from this client-side is ugly, but we do this - * anyway for convenience. - */ -#include "memdebug.h" /* keep this as LAST include */ - #ifdef __VMS /* * vms_show is a global variable, used in main() as parameter for @@ -121,7 +114,7 @@ static void memory_tracking_init(void) curl_free(env); curl_dbg_memdebug(fname); /* this weird stuff here is to make curl_free() get called before - curl_dbg_memdebug() as otherwise memory tracking will log a free() + curl_dbg_memdebug() as otherwise memory tracking will log a curlx_free() without an alloc! */ } /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */ diff --git a/src/tool_msgs.c b/src/tool_msgs.c index ae0b6b9835..b385f75cf8 100644 --- a/src/tool_msgs.c +++ b/src/tool_msgs.c @@ -28,8 +28,6 @@ #include "tool_cb_prg.h" #include "terminal.h" -#include "memdebug.h" /* keep this as LAST include */ - #define WARN_PREFIX "Warning: " #define NOTE_PREFIX "Note: " #define ERROR_PREFIX "curl: " diff --git a/src/tool_operate.c b/src/tool_operate.c index eb591935db..968dc864f9 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -90,8 +90,6 @@ CURL_EXTERN CURLcode curl_easy_perform_ev(CURL *easy); #endif -#include "memdebug.h" /* keep this as LAST include */ - #ifdef CURL_CA_EMBED #ifndef CURL_DECLARED_CURL_CA_EMBED #define CURL_DECLARED_CURL_CA_EMBED @@ -204,7 +202,7 @@ static struct per_transfer *transfersl; /* last node */ static CURLcode add_per_transfer(struct per_transfer **per) { struct per_transfer *p; - p = calloc(1, sizeof(struct per_transfer)); + p = curlx_calloc(1, sizeof(struct per_transfer)); if(!p) return CURLE_OUT_OF_MEMORY; if(!transfers) @@ -246,7 +244,7 @@ static struct per_transfer *del_per_transfer(struct per_transfer *per) else transfersl = p; - free(per); + curlx_free(per); return n; } @@ -770,10 +768,10 @@ skip: curl_easy_cleanup(per->curl); if(outs->alloc_filename) - free(outs->filename); - free(per->url); - free(per->outfile); - free(per->uploadfile); + curlx_free(outs->filename); + curlx_free(per->url); + curlx_free(per->outfile); + curlx_free(per->uploadfile); curl_slist_free_all(per->hdrcbdata.headlist); per->hdrcbdata.headlist = NULL; return result; @@ -785,7 +783,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) /* Check if config->cert is a PKCS#11 URI and set the config->cert_type if * necessary */ if(config->cert && !config->cert_type && is_pkcs11_uri(config->cert)) { - config->cert_type = strdup("ENG"); + config->cert_type = curlx_strdup("ENG"); if(!config->cert_type) return CURLE_OUT_OF_MEMORY; } @@ -793,7 +791,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) /* Check if config->key is a PKCS#11 URI and set the config->key_type if * necessary */ if(config->key && !config->key_type && is_pkcs11_uri(config->key)) { - config->key_type = strdup("ENG"); + config->key_type = curlx_strdup("ENG"); if(!config->key_type) return CURLE_OUT_OF_MEMORY; } @@ -802,7 +800,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) * config->proxy_type if necessary */ if(config->proxy_cert && !config->proxy_cert_type && is_pkcs11_uri(config->proxy_cert)) { - config->proxy_cert_type = strdup("ENG"); + config->proxy_cert_type = curlx_strdup("ENG"); if(!config->proxy_cert_type) return CURLE_OUT_OF_MEMORY; } @@ -811,7 +809,7 @@ static CURLcode set_cert_types(struct OperationConfig *config) * config->proxy_key_type if necessary */ if(config->proxy_key && !config->proxy_key_type && is_pkcs11_uri(config->proxy_key)) { - config->proxy_key_type = strdup("ENG"); + config->proxy_key_type = curlx_strdup("ENG"); if(!config->proxy_key_type) return CURLE_OUT_OF_MEMORY; } @@ -844,7 +842,7 @@ static CURLcode append2query(struct OperationConfig *config, if(uerr) result = urlerr_cvt(uerr); else { - free(per->url); /* free previous URL */ + curlx_free(per->url); /* free previous URL */ per->url = updated; /* use our new URL instead! */ } } @@ -1022,7 +1020,7 @@ static CURLcode setup_outfile(struct OperationConfig *config, char *d = curl_maprintf("%s/%s", config->output_dir, per->outfile); if(!d) return CURLE_WRITE_ERROR; - free(per->outfile); + curlx_free(per->outfile); per->outfile = d; } /* Create the directory hierarchy, if not pre-existent to a multiple @@ -1264,7 +1262,7 @@ static CURLcode single_transfer(struct OperationConfig *config, } per->etag_save = etag_first; /* copy the whole struct */ if(state->uploadfile) { - per->uploadfile = strdup(state->uploadfile); + per->uploadfile = curlx_strdup(state->uploadfile); if(!per->uploadfile || SetHTTPrequest(TOOL_HTTPREQ_PUT, &config->httpreq)) { tool_safefree(per->uploadfile); @@ -1300,7 +1298,7 @@ static CURLcode single_transfer(struct OperationConfig *config, if(glob_inuse(&state->urlglob)) result = glob_next_url(&per->url, &state->urlglob); else if(!state->urlidx) { - per->url = strdup(u->url); + per->url = curlx_strdup(u->url); if(!per->url) result = CURLE_OUT_OF_MEMORY; } @@ -1312,7 +1310,7 @@ static CURLcode single_transfer(struct OperationConfig *config, return result; if(u->outfile) { - per->outfile = strdup(u->outfile); + per->outfile = curlx_strdup(u->outfile); if(!per->outfile) return CURLE_OUT_OF_MEMORY; } @@ -1586,7 +1584,7 @@ static struct contextuv *create_context(curl_socket_t sockfd, { struct contextuv *c; - c = (struct contextuv *) malloc(sizeof(*c)); + c = (struct contextuv *)curlx_malloc(sizeof(*c)); c->sockfd = sockfd; c->uv = uv; @@ -1600,7 +1598,7 @@ static struct contextuv *create_context(curl_socket_t sockfd, static void close_cb(uv_handle_t *handle) { struct contextuv *c = (struct contextuv *) handle->data; - free(c); + curlx_free(c); } static void destroy_context(struct contextuv *c) @@ -2053,7 +2051,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) env = curl_getenv("CURL_CA_BUNDLE"); if(env) { - config->cacert = strdup(env); + config->cacert = curlx_strdup(env); curl_free(env); if(!config->cacert) { result = CURLE_OUT_OF_MEMORY; @@ -2063,7 +2061,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) else { env = curl_getenv("SSL_CERT_DIR"); if(env) { - config->capath = strdup(env); + config->capath = curlx_strdup(env); curl_free(env); if(!config->capath) { result = CURLE_OUT_OF_MEMORY; @@ -2072,7 +2070,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) } env = curl_getenv("SSL_CERT_FILE"); if(env) { - config->cacert = strdup(env); + config->cacert = curlx_strdup(env); curl_free(env); if(!config->cacert) { result = CURLE_OUT_OF_MEMORY; @@ -2088,7 +2086,7 @@ static CURLcode cacertpaths(struct OperationConfig *config) FILE *cafile = tool_execpath("curl-ca-bundle.crt", &cacert); if(cafile) { curlx_fclose(cafile); - config->cacert = strdup(cacert); + config->cacert = curlx_strdup(cacert); if(!config->cacert) { result = CURLE_OUT_OF_MEMORY; goto fail; @@ -2260,7 +2258,7 @@ CURLcode operate(int argc, argv_item_t argv[]) if(found_curlrc) { /* After parse_args so notef knows the verbosity */ notef("Read config file from '%s'", curlrc_path); - free(curlrc_path); + curlx_free(curlrc_path); } if(res) { result = CURLE_OK; diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c index 0d6c2cb6e0..a8b5e94975 100644 --- a/src/tool_operhlp.c +++ b/src/tool_operhlp.c @@ -28,7 +28,6 @@ #include "tool_doswin.h" #include "tool_operhlp.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ void clean_getout(struct OperationConfig *config) { @@ -144,7 +143,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename) if(!newpath) goto fail; uerr = curl_url_set(uh, CURLUPART_PATH, newpath, 0); - free(newpath); + curlx_free(newpath); if(uerr) { result = urlerr_cvt(uerr); goto fail; @@ -154,7 +153,7 @@ CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename) result = urlerr_cvt(uerr); goto fail; } - free(*inurlp); + curlx_free(*inurlp); *inurlp = newurl; result = CURLE_OK; } @@ -206,11 +205,11 @@ CURLcode get_url_file_name(char **filename, const char *url) if(pc) { /* duplicate the string beyond the slash */ - *filename = strdup(pc + 1); + *filename = curlx_strdup(pc + 1); } else { /* no slash => empty string, use default */ - *filename = strdup("curl_response"); + *filename = curlx_strdup("curl_response"); warnf("No remote filename, uses \"%s\"", *filename); } diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 15293c0cc6..b16fc42906 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -32,11 +32,9 @@ #include "tool_util.h" #include "tool_version.h" -#include "memdebug.h" /* keep this as LAST include */ - struct getout *new_getout(struct OperationConfig *config) { - struct getout *node = calloc(1, sizeof(struct getout)); + struct getout *node = curlx_calloc(1, sizeof(struct getout)); struct getout *last = config->url_last; if(node) { static int outnum = 0; @@ -401,7 +399,7 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str) curlx_dyn_init(&obuf, MAX_PROTOSTRING); - protoset = malloc((proto_count + 1) * sizeof(*protoset)); + protoset = curlx_malloc((proto_count + 1) * sizeof(*protoset)); if(!protoset) return PARAM_NO_MEM; @@ -499,14 +497,14 @@ ParameterError proto2num(const char * const *val, char **ostr, const char *str) for(proto = 0; protoset[proto] && !result; proto++) result = curlx_dyn_addf(&obuf, "%s%s", curlx_dyn_len(&obuf) ? "," : "", protoset[proto]); - free((char *) protoset); + curlx_free((char *)protoset); if(result) return PARAM_NO_MEM; if(!curlx_dyn_len(&obuf)) { curlx_dyn_free(&obuf); return PARAM_BAD_USE; } - free(*ostr); + curlx_free(*ostr); *ostr = curlx_dyn_ptr(&obuf); return PARAM_OK; } @@ -592,7 +590,7 @@ static CURLcode checkpasswd(const char *kind, /* for what purpose */ return CURLE_OUT_OF_MEMORY; /* return the new string */ - free(*userpwd); + curlx_free(*userpwd); *userpwd = curlx_dyn_ptr(&dyn); } diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index e7a00cf708..f901e69e78 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -30,7 +30,6 @@ #include "tool_msgs.h" #include "tool_parsecfg.h" #include "tool_util.h" -#include "memdebug.h" /* keep this as LAST include */ /* only acknowledge colon or equals as separators if the option was not specified with an initial dash! */ @@ -96,7 +95,7 @@ ParameterError parseconfig(const char *filename, int max_recursive, if(curlrc) { file = curlx_fopen(curlrc, FOPEN_READTEXT); if(!file) { - free(curlrc); + curlx_free(curlrc); return PARAM_READ_ERROR; } filename = pathalloc = curlrc; @@ -266,11 +265,11 @@ ParameterError parseconfig(const char *filename, int max_recursive, errorf("cannot read config from '%s'", filename); if(!err && resolved) { - *resolved = strdup(filename); + *resolved = curlx_strdup(filename); if(!*resolved) err = PARAM_NO_MEM; } - free(pathalloc); + curlx_free(pathalloc); return err; } diff --git a/src/tool_setopt.c b/src/tool_setopt.c index b7039fbb48..97d469d76d 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -30,7 +30,6 @@ #ifndef CURL_DISABLE_LIBCURL_OPTION #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ /* Lookup tables for converting setopt values back to symbols */ /* For enums, values may be in any order. */ @@ -385,7 +384,7 @@ static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno) ret = easysrc_addf(&easysrc_data, "slist%d = curl_slist_append(slist%d, \"%s\");", *slistno, *slistno, escaped); - free(escaped); + curlx_free(escaped); } return ret; @@ -439,7 +438,7 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, easysrc_addf(&easysrc_code, "curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);", mimeno, escaped); - free(escaped); + curlx_free(escaped); } break; @@ -452,7 +451,7 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, ret = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, NULL);", mimeno); } - free(escaped); + curlx_free(escaped); break; } @@ -477,28 +476,28 @@ static CURLcode libcurl_generate_mime_part(CURL *curl, char *escaped = c_escape(part->encoder, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_encoder(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && filename) { char *escaped = c_escape(filename, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && part->name) { char *escaped = c_escape(part->name, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_name(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && part->type) { char *escaped = c_escape(part->type, ZERO_TERMINATED); ret = easysrc_addf(&easysrc_code, "curl_mime_type(part%d, \"%s\");", mimeno, escaped); - free(escaped); + curlx_free(escaped); } if(!ret && part->headers) { @@ -687,7 +686,7 @@ CURLcode tool_setopt_str(CURL *curl, struct OperationConfig *config, result = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, \"%s\");", name, escaped); - free(escaped); + curlx_free(escaped); } else result = CURLE_OUT_OF_MEMORY; diff --git a/src/tool_setup.h b/src/tool_setup.h index 17c2f420b5..f693fc1dae 100644 --- a/src/tool_setup.h +++ b/src/tool_setup.h @@ -68,6 +68,8 @@ extern FILE *tool_stderr; #ifndef HAVE_STRDUP #include "tool_strdup.h" +#undef Curl_strdup +#define Curl_strdup tool_strdup #endif #ifndef tool_nop_stmt diff --git a/src/tool_ssls.c b/src/tool_ssls.c index 2b67be9baa..7ffd6f7074 100644 --- a/src/tool_ssls.c +++ b/src/tool_ssls.c @@ -30,8 +30,6 @@ #include "tool_ssls.h" #include "tool_parsecfg.h" -#include "memdebug.h" /* keep this as LAST include */ - /* The maximum line length for an ecoded session ticket */ #define MAX_SSLS_LINE (64 * 1024) @@ -127,8 +125,8 @@ out: if(fp) curlx_fclose(fp); curlx_dyn_free(&buf); - free(shmac); - free(sdata); + curlx_free(shmac); + curlx_free(sdata); return r; } @@ -181,7 +179,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr, out: if(r) warnf("Warning: error saving SSL session for '%s': %d", session_key, r); - free(enc); + curlx_free(enc); return r; } diff --git a/src/tool_ssls.h b/src/tool_ssls.h index 7a1b95194d..c06e9427cf 100644 --- a/src/tool_ssls.h +++ b/src/tool_ssls.h @@ -26,7 +26,6 @@ #include "tool_setup.h" #include "tool_operate.h" - CURLcode tool_ssls_load(struct OperationConfig *config, CURLSH *share, const char *filename); CURLcode tool_ssls_save(struct OperationConfig *config, diff --git a/src/tool_stderr.c b/src/tool_stderr.c index 8812f8bf8e..7871ebc0cc 100644 --- a/src/tool_stderr.c +++ b/src/tool_stderr.c @@ -26,8 +26,6 @@ #include "tool_stderr.h" #include "tool_msgs.h" -#include "memdebug.h" /* keep this as LAST include */ - FILE *tool_stderr; void tool_init_stderr(void) diff --git a/src/tool_strdup.c b/src/tool_strdup.c index ff80b56b92..c799d1acdf 100644 --- a/src/tool_strdup.c +++ b/src/tool_strdup.c @@ -22,10 +22,9 @@ * ***************************************************************************/ #include "tool_strdup.h" -#include "memdebug.h" /* keep this as LAST include */ #ifndef HAVE_STRDUP -char *strdup(const char *str) +char *tool_strdup(const char *str) { size_t len; char *newstr; @@ -35,7 +34,7 @@ char *strdup(const char *str) len = strlen(str) + 1; - newstr = malloc(len); + newstr = curlx_malloc(len); if(!newstr) return (char *)NULL; @@ -46,7 +45,7 @@ char *strdup(const char *str) char *memdup0(const char *data, size_t len) { - char *p = malloc(len + 1); + char *p = curlx_malloc(len + 1); if(!p) return NULL; if(len) diff --git a/src/tool_strdup.h b/src/tool_strdup.h index 275be7c5d9..0f121e20fd 100644 --- a/src/tool_strdup.h +++ b/src/tool_strdup.h @@ -26,7 +26,7 @@ #include "tool_setup.h" #ifndef HAVE_STRDUP -extern char *strdup(const char *str); +extern char *tool_strdup(const char *str); #endif char *memdup0(const char *data, size_t len); diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c index 7185e80f66..9ea8a274fa 100644 --- a/src/tool_urlglob.c +++ b/src/tool_urlglob.c @@ -28,7 +28,6 @@ #include "tool_urlglob.h" #include "tool_vms.h" #include "tool_strdup.h" -#include "memdebug.h" /* keep this as LAST include */ static CURLcode globerror(struct URLGlob *glob, const char *err, size_t pos, CURLcode error) @@ -45,7 +44,7 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len) pat->globindex = -1; pat->c.set.size = 0; pat->c.set.idx = 0; - pat->c.set.elem = malloc(sizeof(char *)); + pat->c.set.elem = curlx_malloc(sizeof(char *)); if(!pat->c.set.elem) return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); @@ -137,10 +136,10 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp, if(!palloc) { palloc = 5; /* a reasonable default */ - elem = malloc(palloc * sizeof(char *)); + elem = curlx_malloc(palloc * sizeof(char *)); } else if(size >= palloc) { - char **arr = realloc(elem, palloc * 2 * sizeof(char *)); + char **arr = curlx_realloc(elem, palloc * 2 * sizeof(char *)); if(!arr) { result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); goto error; @@ -154,8 +153,8 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp, goto error; } - elem[size] = - strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : ""); + elem[size] = curlx_strdup(curlx_dyn_ptr(&glob->buf) ? + curlx_dyn_ptr(&glob->buf) : ""); if(!elem[size]) { result = globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY); goto error; @@ -206,7 +205,7 @@ error: for(i = 0; i < size; i++) tool_safefree(elem[i]); } - free(elem); + curlx_free(elem); return result; } @@ -387,7 +386,8 @@ static CURLcode add_glob(struct URLGlob *glob, size_t pos) struct URLPattern *np = NULL; glob->palloc *= 2; if(glob->pnum < 255) { /* avoid ridiculous amounts */ - np = realloc(glob->pattern, glob->palloc * sizeof(struct URLPattern)); + np = curlx_realloc(glob->pattern, + glob->palloc * sizeof(struct URLPattern)); if(!np) return globerror(glob, NULL, pos, CURLE_OUT_OF_MEMORY); } @@ -491,7 +491,7 @@ CURLcode glob_url(struct URLGlob *glob, char *url, curl_off_t *urlnum, memset(glob, 0, sizeof(struct URLGlob)); curlx_dyn_init(&glob->buf, 1024*1024); - glob->pattern = malloc(2 * sizeof(struct URLPattern)); + glob->pattern = curlx_malloc(2 * sizeof(struct URLPattern)); if(!glob->pattern) return CURLE_OUT_OF_MEMORY; glob->palloc = 2; @@ -617,7 +617,7 @@ CURLcode glob_next_url(char **globbed, struct URLGlob *glob) } *globbed = - strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : ""); + curlx_strdup(curlx_dyn_ptr(&glob->buf) ? curlx_dyn_ptr(&glob->buf) : ""); if(!*globbed) return CURLE_OUT_OF_MEMORY; diff --git a/src/tool_util.c b/src/tool_util.c index cb64f9a0b9..43dd096783 100644 --- a/src/tool_util.c +++ b/src/tool_util.c @@ -24,7 +24,6 @@ #include "tool_setup.h" #include "tool_util.h" -#include "memdebug.h" /* keep this as LAST include */ #ifdef _WIN32 diff --git a/src/tool_vms.c b/src/tool_vms.c index fac0cfc4dd..75aa7d5370 100644 --- a/src/tool_vms.c +++ b/src/tool_vms.c @@ -32,7 +32,6 @@ #include "curlmsg_vms.h" #include "tool_vms.h" -#include "memdebug.h" /* keep this as LAST include */ void decc$__posix_exit(int __status); void decc$exit(int __status); diff --git a/src/tool_writeout.c b/src/tool_writeout.c index 52b35345f4..f846add4e3 100644 --- a/src/tool_writeout.c +++ b/src/tool_writeout.c @@ -26,7 +26,6 @@ #include "tool_cfgable.h" #include "tool_writeout.h" #include "tool_writeout_json.h" -#include "memdebug.h" /* keep this as LAST include */ static int writeTime(FILE *stream, const struct writeoutvar *wovar, struct per_transfer *per, CURLcode per_result, diff --git a/src/tool_xattr.c b/src/tool_xattr.c index fb0669106e..b111c7b843 100644 --- a/src/tool_xattr.c +++ b/src/tool_xattr.c @@ -24,8 +24,6 @@ #include "tool_setup.h" #include "tool_xattr.h" -#include "memdebug.h" /* keep this as LAST include */ - #ifdef USE_XATTR /* mapping table of curl metadata to extended attribute names */ diff --git a/src/var.c b/src/var.c index 5cedf1d24a..08269e1db7 100644 --- a/src/var.c +++ b/src/var.c @@ -33,7 +33,6 @@ #include "tool_writeout_json.h" #include "tool_strdup.h" #include "var.h" -#include "memdebug.h" /* keep this as LAST include */ #define MAX_EXPAND_CONTENT 10000000 #define MAX_VAR_LEN 128 /* max length of a name */ @@ -45,8 +44,8 @@ void varcleanup(void) while(list) { struct tool_var *t = list; list = list->next; - free(CURL_UNCONST(t->content)); - free(t); + curlx_free(CURL_UNCONST(t->content)); + curlx_free(t); } } @@ -192,7 +191,7 @@ static ParameterError varfunc(char *c, /* content */ break; } if(alloc) - free(c); + curlx_free(c); clen = curlx_dyn_len(out); c = memdup0(curlx_dyn_ptr(out), clen); @@ -203,7 +202,7 @@ static ParameterError varfunc(char *c, /* content */ alloc = TRUE; } if(alloc) - free(c); + curlx_free(c); if(err) curlx_dyn_free(out); return err; @@ -359,7 +358,7 @@ static ParameterError addvariable(const char *name, if(check) notef("Overwriting variable '%s'", check->name); - p = calloc(1, sizeof(struct tool_var) + nlen); + p = curlx_calloc(1, sizeof(struct tool_var) + nlen); if(p) { memcpy(p->name, name, nlen); /* the null termination byte is already present from above */ @@ -372,7 +371,7 @@ static ParameterError addvariable(const char *name, global->variables = p; return PARAM_OK; } - free(p); + curlx_free(p); } return PARAM_NO_MEM; } @@ -496,7 +495,7 @@ ParameterError setvariable(const char *input) err = addvariable(name, nlen, content, clen, contalloc); if(err) { if(contalloc) - free(content); + curlx_free(content); } return err; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 677a17cd99..0371159d68 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -25,7 +25,6 @@ # scripts used in test cases TESTSCRIPTS = \ test1119.pl \ - test1132.pl \ test1135.pl \ test1139.pl \ test1140.pl \ diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index bc3abbc7d8..18c6969391 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -152,7 +152,7 @@ test1093 test1094 test1095 test1096 test1097 test1098 test1099 test1100 \ test1101 test1102 test1103 test1104 test1105 test1106 test1107 test1108 \ test1109 test1110 test1111 test1112 test1113 test1114 test1115 test1116 \ test1117 test1118 test1119 test1120 test1121 test1122 test1123 test1124 \ -test1125 test1126 test1127 test1128 test1129 test1130 test1131 test1132 \ +test1125 test1126 test1127 test1128 test1129 test1130 test1131 \ test1133 test1134 test1135 test1136 test1137 test1138 test1139 test1140 \ test1141 test1142 test1143 test1144 test1145 test1146 test1147 test1148 \ test1149 test1150 test1151 test1152 test1153 test1154 test1155 test1156 \ diff --git a/tests/data/test1132 b/tests/data/test1132 deleted file mode 100644 index d0ef42a24e..0000000000 --- a/tests/data/test1132 +++ /dev/null @@ -1,21 +0,0 @@ - - - -source analysis -memory-includes - - - -# -# Client-side - - -Verify memory #include files in libcurl's C source files - - - -%SRCDIR/test1132.pl %SRCDIR/../lib - - - - diff --git a/tests/libtest/cli_h2_pausing.c b/tests/libtest/cli_h2_pausing.c index 0f06dadd52..25b798af4b 100644 --- a/tests/libtest/cli_h2_pausing.c +++ b/tests/libtest/cli_h2_pausing.c @@ -26,7 +26,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static void usage_h2_pausing(const char *msg) { diff --git a/tests/libtest/cli_h2_serverpush.c b/tests/libtest/cli_h2_serverpush.c index ad3ae4f914..80d8c03136 100644 --- a/tests/libtest/cli_h2_serverpush.c +++ b/tests/libtest/cli_h2_serverpush.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static FILE *out_download = NULL; diff --git a/tests/libtest/cli_h2_upgrade_extreme.c b/tests/libtest/cli_h2_upgrade_extreme.c index b5c6c31b1b..bc28a6f4d0 100644 --- a/tests/libtest/cli_h2_upgrade_extreme.c +++ b/tests/libtest/cli_h2_upgrade_extreme.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static size_t write_h2_upg_extreme_cb(char *ptr, size_t size, size_t nmemb, void *opaque) diff --git a/tests/libtest/cli_hx_download.c b/tests/libtest/cli_hx_download.c index 82e8c1b70d..a7f5d20090 100644 --- a/tests/libtest/cli_hx_download.c +++ b/tests/libtest/cli_hx_download.c @@ -25,8 +25,6 @@ #include "testtrace.h" -#include "curl_mem_undef.h" - #if defined(USE_QUICHE) || defined(USE_OPENSSL) #include #endif @@ -45,8 +43,6 @@ #include #endif -#include "memdebug.h" - static int verbose_d = 1; struct transfer_d { @@ -346,8 +342,8 @@ static CURLcode test_cli_hx_download(const char *URL) pause_offset = (size_t)num; break; case 'r': - free(resolve); - resolve = strdup(coptarg); + curlx_free(resolve); + resolve = curlx_strdup(coptarg); break; case 'T': if(!curlx_str_number(&opt, &num, LONG_MAX)) @@ -407,7 +403,7 @@ static CURLcode test_cli_hx_download(const char *URL) curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL); curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS); - transfer_d = calloc(transfer_count_d, sizeof(*transfer_d)); + transfer_d = curlx_calloc(transfer_count_d, sizeof(*transfer_d)); if(!transfer_d) { curl_mfprintf(stderr, "error allocating transfer structs\n"); res = (CURLcode)1; @@ -559,7 +555,7 @@ cleanup: else /* on success we expect ssl to have been checked */ assert(t->checked_ssl); } - free(transfer_d); + curlx_free(transfer_d); } curl_share_cleanup(share); @@ -569,7 +565,7 @@ cleanup: optcleanup: - free(resolve); + curlx_free(resolve); return res; } diff --git a/tests/libtest/cli_hx_upload.c b/tests/libtest/cli_hx_upload.c index f0183f6df2..f7036509fe 100644 --- a/tests/libtest/cli_hx_upload.c +++ b/tests/libtest/cli_hx_upload.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int verbose_u = 1; @@ -358,7 +357,7 @@ static CURLcode test_cli_hx_upload(const char *URL) curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL); curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS); - transfer_u = calloc(transfer_count_u, sizeof(*transfer_u)); + transfer_u = curlx_calloc(transfer_count_u, sizeof(*transfer_u)); if(!transfer_u) { curl_mfprintf(stderr, "error allocating transfer structs\n"); res = (CURLcode)1; @@ -539,7 +538,7 @@ cleanup: curl_mime_free(t->mime); } } - free(transfer_u); + curlx_free(transfer_u); } curl_share_cleanup(share); diff --git a/tests/libtest/cli_tls_session_reuse.c b/tests/libtest/cli_tls_session_reuse.c index 2f6bde43e3..aa56a0e28c 100644 --- a/tests/libtest/cli_tls_session_reuse.c +++ b/tests/libtest/cli_tls_session_reuse.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int tse_found_tls_session = FALSE; diff --git a/tests/libtest/cli_upload_pausing.c b/tests/libtest/cli_upload_pausing.c index 441ce899a0..042eddd7d7 100644 --- a/tests/libtest/cli_upload_pausing.c +++ b/tests/libtest/cli_upload_pausing.c @@ -26,7 +26,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static size_t total_read = 0; diff --git a/tests/libtest/cli_ws_data.c b/tests/libtest/cli_ws_data.c index aa43bc6058..2276f0c92c 100644 --- a/tests/libtest/cli_ws_data.c +++ b/tests/libtest/cli_ws_data.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifndef CURL_DISABLE_WEBSOCKETS @@ -83,8 +82,8 @@ static CURLcode test_ws_data_m2_echo(const char *url, size_t i, scount = count, rcount = count; int rblock, sblock; - send_buf = calloc(1, plen_max + 1); - recv_buf = calloc(1, plen_max + 1); + send_buf = curlx_calloc(1, plen_max + 1); + recv_buf = curlx_calloc(1, plen_max + 1); if(!send_buf || !recv_buf) { r = CURLE_OUT_OF_MEMORY; goto out; @@ -184,8 +183,8 @@ out: ws_close(curl); curl_easy_cleanup(curl); } - free(send_buf); - free(recv_buf); + curlx_free(send_buf); + curlx_free(recv_buf); return r; } @@ -294,8 +293,8 @@ static CURLcode test_ws_data_m1_echo(const char *url, curl_mfprintf(stderr, "test_ws_data_m1_echo(min=%zu, max=%zu)\n", plen_min, plen_max); memset(&m1_ctx, 0, sizeof(m1_ctx)); - m1_ctx.send_buf = calloc(1, plen_max + 1); - m1_ctx.recv_buf = calloc(1, plen_max + 1); + m1_ctx.send_buf = curlx_calloc(1, plen_max + 1); + m1_ctx.recv_buf = curlx_calloc(1, plen_max + 1); if(!m1_ctx.send_buf || !m1_ctx.recv_buf) { r = CURLE_OUT_OF_MEMORY; goto out; @@ -389,8 +388,8 @@ out: if(m1_ctx.curl) { curl_easy_cleanup(m1_ctx.curl); } - free(m1_ctx.send_buf); - free(m1_ctx.recv_buf); + curlx_free(m1_ctx.send_buf); + curlx_free(m1_ctx.recv_buf); return r; } diff --git a/tests/libtest/cli_ws_pingpong.c b/tests/libtest/cli_ws_pingpong.c index 0a8e957aa4..8449b9d127 100644 --- a/tests/libtest/cli_ws_pingpong.c +++ b/tests/libtest/cli_ws_pingpong.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifndef CURL_DISABLE_WEBSOCKETS diff --git a/tests/libtest/first.c b/tests/libtest/first.c index a8e2e91cf0..2f65530882 100644 --- a/tests/libtest/first.c +++ b/tests/libtest/first.c @@ -27,8 +27,6 @@ #include /* for setlocale() */ #endif -#include "memdebug.h" - int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc, struct timeval *tv) { diff --git a/tests/libtest/lib1156.c b/tests/libtest/lib1156.c index 6ceb6894e7..758f6e3f1a 100644 --- a/tests/libtest/lib1156.c +++ b/tests/libtest/lib1156.c @@ -34,8 +34,6 @@ */ -#include "memdebug.h" - #define F_RESUME (1 << 0) /* resume/range. */ #define F_HTTP416 (1 << 1) /* Server returns http code 416. */ #define F_FAIL (1 << 2) /* Fail on error. */ diff --git a/tests/libtest/lib1485.c b/tests/libtest/lib1485.c index 7fea83317c..828e1ede74 100644 --- a/tests/libtest/lib1485.c +++ b/tests/libtest/lib1485.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t1485_transfer_status { CURL *curl; curl_off_t out_len; diff --git a/tests/libtest/lib1500.c b/tests/libtest/lib1500.c index 5fe8e7ab4f..921d1ce8b1 100644 --- a/tests/libtest/lib1500.c +++ b/tests/libtest/lib1500.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1500(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1501.c b/tests/libtest/lib1501.c index 5b5e64c48c..cd1cd874f7 100644 --- a/tests/libtest/lib1501.c +++ b/tests/libtest/lib1501.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1501(const char *URL) { static const long HANG_TIMEOUT = 30 * 1000; diff --git a/tests/libtest/lib1502.c b/tests/libtest/lib1502.c index 527f969b11..1546acfaa8 100644 --- a/tests/libtest/lib1502.c +++ b/tests/libtest/lib1502.c @@ -31,8 +31,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1502(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1506.c b/tests/libtest/lib1506.c index 5790f3baeb..8b986c59a0 100644 --- a/tests/libtest/lib1506.c +++ b/tests/libtest/lib1506.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1506(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1507.c b/tests/libtest/lib1507.c index d9f85a3318..ffdaa50df6 100644 --- a/tests/libtest/lib1507.c +++ b/tests/libtest/lib1507.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1507_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { (void)ptr; diff --git a/tests/libtest/lib1508.c b/tests/libtest/lib1508.c index b7b47daa3f..446e8231a5 100644 --- a/tests/libtest/lib1508.c +++ b/tests/libtest/lib1508.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1508(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1509.c b/tests/libtest/lib1509.c index 3ab4feea8b..16935de7a7 100644 --- a/tests/libtest/lib1509.c +++ b/tests/libtest/lib1509.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t realHeaderSize = 0; static size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1510.c b/tests/libtest/lib1510.c index e914d48eb7..7a70763813 100644 --- a/tests/libtest/lib1510.c +++ b/tests/libtest/lib1510.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1510(const char *URL) { static const int NUM_URLS = 4; diff --git a/tests/libtest/lib1511.c b/tests/libtest/lib1511.c index de09d2a6fa..fb65dcae98 100644 --- a/tests/libtest/lib1511.c +++ b/tests/libtest/lib1511.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1511(const char *URL) { long unmet; diff --git a/tests/libtest/lib1512.c b/tests/libtest/lib1512.c index dd80163d43..16648d7e56 100644 --- a/tests/libtest/lib1512.c +++ b/tests/libtest/lib1512.c @@ -30,8 +30,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1512(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1513.c b/tests/libtest/lib1513.c index c86c5185e2..8bf1613fa1 100644 --- a/tests/libtest/lib1513.c +++ b/tests/libtest/lib1513.c @@ -30,8 +30,6 @@ #include "first.h" -#include "memdebug.h" - static int progressKiller(void *arg, double dltotal, double dlnow, diff --git a/tests/libtest/lib1514.c b/tests/libtest/lib1514.c index fc7e33e3d3..fa0aa07424 100644 --- a/tests/libtest/lib1514.c +++ b/tests/libtest/lib1514.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - struct t1514_WriteThis { char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib1515.c b/tests/libtest/lib1515.c index 679a413c69..7833f06a10 100644 --- a/tests/libtest/lib1515.c +++ b/tests/libtest/lib1515.c @@ -31,7 +31,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #define DNS_TIMEOUT 1L diff --git a/tests/libtest/lib1517.c b/tests/libtest/lib1517.c index d8ad3b753b..cebdeab0a1 100644 --- a/tests/libtest/lib1517.c +++ b/tests/libtest/lib1517.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t1517_WriteThis { const char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib1518.c b/tests/libtest/lib1518.c index 63e861910d..1ebe957af3 100644 --- a/tests/libtest/lib1518.c +++ b/tests/libtest/lib1518.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test inspired by github issue 3340 */ static size_t t1518_write_cb(char *buffer, size_t size, size_t nitems, diff --git a/tests/libtest/lib1520.c b/tests/libtest/lib1520.c index e61727eadc..4cf54388eb 100644 --- a/tests/libtest/lib1520.c +++ b/tests/libtest/lib1520.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct upload_status { int lines_read; }; diff --git a/tests/libtest/lib1522.c b/tests/libtest/lib1522.c index 3423f4777c..1ac2332e81 100644 --- a/tests/libtest/lib1522.c +++ b/tests/libtest/lib1522.c @@ -26,7 +26,6 @@ /* test case and code based on https://github.com/curl/curl/issues/2847 */ #include "testtrace.h" -#include "memdebug.h" static int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose) diff --git a/tests/libtest/lib1523.c b/tests/libtest/lib1523.c index 5c9a01a5eb..711aa3f714 100644 --- a/tests/libtest/lib1523.c +++ b/tests/libtest/lib1523.c @@ -25,8 +25,6 @@ /* test case and code based on https://github.com/curl/curl/issues/3927 */ -#include "memdebug.h" - static int dload_progress_cb(void *a, curl_off_t b, curl_off_t c, curl_off_t d, curl_off_t e) { diff --git a/tests/libtest/lib1525.c b/tests/libtest/lib1525.c index 7e7d98ef79..c9a1e1514f 100644 --- a/tests/libtest/lib1525.c +++ b/tests/libtest/lib1525.c @@ -30,8 +30,6 @@ #include "first.h" -#include "memdebug.h" - static const char t1525_testdata[] = "Hello Cloud!\n"; static size_t t1525_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1526.c b/tests/libtest/lib1526.c index bf2a07ee9d..031f8bfd27 100644 --- a/tests/libtest/lib1526.c +++ b/tests/libtest/lib1526.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - static const char t1526_testdata[] = "Hello Cloud!\n"; static size_t t1526_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1527.c b/tests/libtest/lib1527.c index 3624728687..1d9a582132 100644 --- a/tests/libtest/lib1527.c +++ b/tests/libtest/lib1527.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - static const char t1527_testdata[] = "Hello Cloud!\n"; static size_t t1527_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1528.c b/tests/libtest/lib1528.c index 98bd2bdaf1..e1dd3657fe 100644 --- a/tests/libtest/lib1528.c +++ b/tests/libtest/lib1528.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1528(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1529.c b/tests/libtest/lib1529.c index ae86b61a5e..24cdd78b03 100644 --- a/tests/libtest/lib1529.c +++ b/tests/libtest/lib1529.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1529(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1530.c b/tests/libtest/lib1530.c index 19b0d9cbde..6cb6d59e87 100644 --- a/tests/libtest/lib1530.c +++ b/tests/libtest/lib1530.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static curl_socket_t opensocket(void *clientp, curlsocktype purpose, struct curl_sockaddr *address) diff --git a/tests/libtest/lib1531.c b/tests/libtest/lib1531.c index 65b20c2993..a3554434e6 100644 --- a/tests/libtest/lib1531.c +++ b/tests/libtest/lib1531.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1531(const char *URL) { static char const testData[] = ".abc\0xyz"; diff --git a/tests/libtest/lib1532.c b/tests/libtest/lib1532.c index 83a826de32..e1c5c04702 100644 --- a/tests/libtest/lib1532.c +++ b/tests/libtest/lib1532.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_RESPONSE_CODE */ static CURLcode test_lib1532(const char *URL) diff --git a/tests/libtest/lib1533.c b/tests/libtest/lib1533.c index 1c60172734..a2d541c412 100644 --- a/tests/libtest/lib1533.c +++ b/tests/libtest/lib1533.c @@ -31,8 +31,6 @@ #include "first.h" -#include "memdebug.h" - struct cb_data { CURL *curl; int response_received; diff --git a/tests/libtest/lib1534.c b/tests/libtest/lib1534.c index af1c0bd520..377df3b2fe 100644 --- a/tests/libtest/lib1534.c +++ b/tests/libtest/lib1534.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_FILETIME */ static CURLcode test_lib1534(const char *URL) diff --git a/tests/libtest/lib1535.c b/tests/libtest/lib1535.c index c0e0689d98..c49c3076df 100644 --- a/tests/libtest/lib1535.c +++ b/tests/libtest/lib1535.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_PROTOCOL */ static CURLcode test_lib1535(const char *URL) diff --git a/tests/libtest/lib1536.c b/tests/libtest/lib1536.c index 3219724b9a..f89b50a195 100644 --- a/tests/libtest/lib1536.c +++ b/tests/libtest/lib1536.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test CURLINFO_SCHEME */ static CURLcode test_lib1536(const char *URL) diff --git a/tests/libtest/lib1537.c b/tests/libtest/lib1537.c index cb35fb1908..f521986ebc 100644 --- a/tests/libtest/lib1537.c +++ b/tests/libtest/lib1537.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1537(const char *URL) { const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, diff --git a/tests/libtest/lib1538.c b/tests/libtest/lib1538.c index 9aaec8171a..2a8830c5cc 100644 --- a/tests/libtest/lib1538.c +++ b/tests/libtest/lib1538.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1538(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1540.c b/tests/libtest/lib1540.c index 7f91234356..849431e796 100644 --- a/tests/libtest/lib1540.c +++ b/tests/libtest/lib1540.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" struct t1540_transfer_status { CURL *curl; diff --git a/tests/libtest/lib1541.c b/tests/libtest/lib1541.c index 150fd2e30b..c39bee989c 100644 --- a/tests/libtest/lib1541.c +++ b/tests/libtest/lib1541.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t1541_transfer_status { CURL *curl; int hd_count; diff --git a/tests/libtest/lib1542.c b/tests/libtest/lib1542.c index 9fc9f17efb..9a6ba0b36e 100644 --- a/tests/libtest/lib1542.c +++ b/tests/libtest/lib1542.c @@ -33,7 +33,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib1542(const char *URL) { diff --git a/tests/libtest/lib1549.c b/tests/libtest/lib1549.c index 10d3183810..fa9515e4f6 100644 --- a/tests/libtest/lib1549.c +++ b/tests/libtest/lib1549.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib1549(const char *URL) { diff --git a/tests/libtest/lib1550.c b/tests/libtest/lib1550.c index 566cbfa192..b328dd27bc 100644 --- a/tests/libtest/lib1550.c +++ b/tests/libtest/lib1550.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #include static CURLcode test_lib1550(const char *URL) diff --git a/tests/libtest/lib1551.c b/tests/libtest/lib1551.c index 80020f5556..ce4989a616 100644 --- a/tests/libtest/lib1551.c +++ b/tests/libtest/lib1551.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #include static CURLcode test_lib1551(const char *URL) diff --git a/tests/libtest/lib1552.c b/tests/libtest/lib1552.c index d0c3469d4c..bceacd354c 100644 --- a/tests/libtest/lib1552.c +++ b/tests/libtest/lib1552.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1552(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib1553.c b/tests/libtest/lib1553.c index fa753ac231..d1eaefee4a 100644 --- a/tests/libtest/lib1553.c +++ b/tests/libtest/lib1553.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int t1553_xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, diff --git a/tests/libtest/lib1554.c b/tests/libtest/lib1554.c index a23d713e63..f330b2df7d 100644 --- a/tests/libtest/lib1554.c +++ b/tests/libtest/lib1554.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static const char *ldata_names[] = { "NONE", "SHARE", diff --git a/tests/libtest/lib1555.c b/tests/libtest/lib1555.c index 4ebde5c74c..001a8f5bae 100644 --- a/tests/libtest/lib1555.c +++ b/tests/libtest/lib1555.c @@ -27,8 +27,6 @@ #include "first.h" -#include "memdebug.h" - static CURL *t1555_curl; static int progressCallback(void *arg, diff --git a/tests/libtest/lib1556.c b/tests/libtest/lib1556.c index 4987fc9f09..e852bb3224 100644 --- a/tests/libtest/lib1556.c +++ b/tests/libtest/lib1556.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct headerinfo { size_t largest; }; diff --git a/tests/libtest/lib1557.c b/tests/libtest/lib1557.c index 1c2785dbe3..28162a1b03 100644 --- a/tests/libtest/lib1557.c +++ b/tests/libtest/lib1557.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1557(const char *URL) { CURLM *multi = NULL; diff --git a/tests/libtest/lib1558.c b/tests/libtest/lib1558.c index 1bbc0f77b7..d299405fe2 100644 --- a/tests/libtest/lib1558.c +++ b/tests/libtest/lib1558.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1558(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1559.c b/tests/libtest/lib1559.c index 1aa0f830c7..c6851918a6 100644 --- a/tests/libtest/lib1559.c +++ b/tests/libtest/lib1559.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1559(const char *URL) { static const int EXCESSIVE = 10*1000*1000; @@ -38,7 +36,7 @@ static CURLcode test_lib1559(const char *URL) global_init(CURL_GLOBAL_ALL); easy_init(curl); - longurl = malloc(EXCESSIVE); + longurl = curlx_malloc(EXCESSIVE); if(!longurl) { res = TEST_ERR_MAJOR_BAD; goto test_cleanup; @@ -70,7 +68,7 @@ static CURLcode test_lib1559(const char *URL) } test_cleanup: - free(longurl); + curlx_free(longurl); curl_easy_cleanup(curl); curl_global_cleanup(); diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index db85fe7382..2f6608108c 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -35,8 +35,6 @@ #define USE_IDN #endif -#include "memdebug.h" /* LAST include file */ - static int checkparts(CURLU *u, const char *in, const char *wanted, unsigned int getflags) { diff --git a/tests/libtest/lib1564.c b/tests/libtest/lib1564.c index 42b3a07d1a..23d0c2cd6f 100644 --- a/tests/libtest/lib1564.c +++ b/tests/libtest/lib1564.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define WAKEUP_NUM 10 static CURLcode test_lib1564(const char *URL) diff --git a/tests/libtest/lib1565.c b/tests/libtest/lib1565.c index 7e983978e7..506959dd90 100644 --- a/tests/libtest/lib1565.c +++ b/tests/libtest/lib1565.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #ifdef HAVE_PTHREAD_H #include diff --git a/tests/libtest/lib1567.c b/tests/libtest/lib1567.c index e001615725..539da3c34f 100644 --- a/tests/libtest/lib1567.c +++ b/tests/libtest/lib1567.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #include static CURLcode test_lib1567(const char *URL) diff --git a/tests/libtest/lib1568.c b/tests/libtest/lib1568.c index 89dd83480d..0db1e49e2f 100644 --- a/tests/libtest/lib1568.c +++ b/tests/libtest/lib1568.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1568(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1569.c b/tests/libtest/lib1569.c index c2fd27bfe1..44d77a5d45 100644 --- a/tests/libtest/lib1569.c +++ b/tests/libtest/lib1569.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1569(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1571.c b/tests/libtest/lib1571.c index 622be2f643..8b29a9a1bf 100644 --- a/tests/libtest/lib1571.c +++ b/tests/libtest/lib1571.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1571(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib1576.c b/tests/libtest/lib1576.c index 203ef2b989..9a5d415193 100644 --- a/tests/libtest/lib1576.c +++ b/tests/libtest/lib1576.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static char t1576_testdata[] = "request indicates that the client, which made"; static size_t t1576_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1582.c b/tests/libtest/lib1582.c index 0e209beee4..e1877a99ac 100644 --- a/tests/libtest/lib1582.c +++ b/tests/libtest/lib1582.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1582(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib1591.c b/tests/libtest/lib1591.c index 3031ba1bb7..42761c3065 100644 --- a/tests/libtest/lib1591.c +++ b/tests/libtest/lib1591.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - static size_t consumed = 0; static size_t t1591_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib1593.c b/tests/libtest/lib1593.c index 5b6e57d4f7..f8d7be9d72 100644 --- a/tests/libtest/lib1593.c +++ b/tests/libtest/lib1593.c @@ -26,8 +26,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1593(const char *URL) { struct curl_slist *header = NULL; diff --git a/tests/libtest/lib1594.c b/tests/libtest/lib1594.c index 5c8db3ae92..6cf5cace53 100644 --- a/tests/libtest/lib1594.c +++ b/tests/libtest/lib1594.c @@ -26,8 +26,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1594(const char *URL) { struct curl_slist *header = NULL; diff --git a/tests/libtest/lib1597.c b/tests/libtest/lib1597.c index 251016641e..a338a53944 100644 --- a/tests/libtest/lib1597.c +++ b/tests/libtest/lib1597.c @@ -26,8 +26,6 @@ #include "first.h" -#include "memdebug.h" - struct pair { const char *in; CURLcode *exp; diff --git a/tests/libtest/lib1598.c b/tests/libtest/lib1598.c index 4120916ff0..8d9ec7eb8e 100644 --- a/tests/libtest/lib1598.c +++ b/tests/libtest/lib1598.c @@ -29,8 +29,6 @@ #include "first.h" -#include "memdebug.h" - /* * carefully not leak memory on OOM */ diff --git a/tests/libtest/lib1900.c b/tests/libtest/lib1900.c index 2f0954bb6c..04ce5aa9f1 100644 --- a/tests/libtest/lib1900.c +++ b/tests/libtest/lib1900.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1900(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1901.c b/tests/libtest/lib1901.c index cb66001f9b..4494633b94 100644 --- a/tests/libtest/lib1901.c +++ b/tests/libtest/lib1901.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1901_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { static const char *chunks[] = { diff --git a/tests/libtest/lib1902.c b/tests/libtest/lib1902.c index 8e5929e338..e114554ec5 100644 --- a/tests/libtest/lib1902.c +++ b/tests/libtest/lib1902.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1902(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1903.c b/tests/libtest/lib1903.c index fc2858d5ee..19c2f50e19 100644 --- a/tests/libtest/lib1903.c +++ b/tests/libtest/lib1903.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1903(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1905.c b/tests/libtest/lib1905.c index 600e696238..d1fdba4d2e 100644 --- a/tests/libtest/lib1905.c +++ b/tests/libtest/lib1905.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1905(const char *URL) { CURLSH *share = NULL; diff --git a/tests/libtest/lib1906.c b/tests/libtest/lib1906.c index da0f9f56b9..07404f8b90 100644 --- a/tests/libtest/lib1906.c +++ b/tests/libtest/lib1906.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1906(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1907.c b/tests/libtest/lib1907.c index 0a3556719b..ebf106d3b1 100644 --- a/tests/libtest/lib1907.c +++ b/tests/libtest/lib1907.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1907(const char *URL) { char *url_after; diff --git a/tests/libtest/lib1908.c b/tests/libtest/lib1908.c index ac841ca1a1..2ceb04d5a2 100644 --- a/tests/libtest/lib1908.c +++ b/tests/libtest/lib1908.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1908(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1910.c b/tests/libtest/lib1910.c index ebe86c1245..4f22777526 100644 --- a/tests/libtest/lib1910.c +++ b/tests/libtest/lib1910.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1910(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1911.c b/tests/libtest/lib1911.c index 46c73ffb36..0f88752b6f 100644 --- a/tests/libtest/lib1911.c +++ b/tests/libtest/lib1911.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* The maximum string length limit (CURL_MAX_INPUT_LENGTH) is an internal define not publicly exposed so we set our own */ #define MAX_INPUT_LENGTH 8000000 diff --git a/tests/libtest/lib1912.c b/tests/libtest/lib1912.c index 0dd246e461..76ba51c447 100644 --- a/tests/libtest/lib1912.c +++ b/tests/libtest/lib1912.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define print_err(name, exp) \ curl_mfprintf(stderr, "Type mismatch for CURLOPT_%s (expected %s)\n", \ name, exp) diff --git a/tests/libtest/lib1913.c b/tests/libtest/lib1913.c index cea7a6c6ec..b4b4ab720f 100644 --- a/tests/libtest/lib1913.c +++ b/tests/libtest/lib1913.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1913(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib1915.c b/tests/libtest/lib1915.c index e47ae9ee80..367533aef6 100644 --- a/tests/libtest/lib1915.c +++ b/tests/libtest/lib1915.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" struct state { int index; diff --git a/tests/libtest/lib1916.c b/tests/libtest/lib1916.c index 24583ab8a1..4c66b1b97e 100644 --- a/tests/libtest/lib1916.c +++ b/tests/libtest/lib1916.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1916(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1918.c b/tests/libtest/lib1918.c index de9252107b..d995639164 100644 --- a/tests/libtest/lib1918.c +++ b/tests/libtest/lib1918.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1918(const char *URL) { const struct curl_easyoption *o; diff --git a/tests/libtest/lib1919.c b/tests/libtest/lib1919.c index a619850dc7..79d31810a4 100644 --- a/tests/libtest/lib1919.c +++ b/tests/libtest/lib1919.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1919(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1933.c b/tests/libtest/lib1933.c index bdd914a641..8b02f16aa7 100644 --- a/tests/libtest/lib1933.c +++ b/tests/libtest/lib1933.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1933(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1934.c b/tests/libtest/lib1934.c index 2cffaa9bc7..465dfeb5de 100644 --- a/tests/libtest/lib1934.c +++ b/tests/libtest/lib1934.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1934(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1935.c b/tests/libtest/lib1935.c index 4f6a1ebb73..61382399a3 100644 --- a/tests/libtest/lib1935.c +++ b/tests/libtest/lib1935.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1935(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1936.c b/tests/libtest/lib1936.c index 438cf92c58..20b170397e 100644 --- a/tests/libtest/lib1936.c +++ b/tests/libtest/lib1936.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1936(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1937.c b/tests/libtest/lib1937.c index 4903f7409a..c6fb120b6a 100644 --- a/tests/libtest/lib1937.c +++ b/tests/libtest/lib1937.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1937(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1938.c b/tests/libtest/lib1938.c index c0bfb6b8ce..b585c53c01 100644 --- a/tests/libtest/lib1938.c +++ b/tests/libtest/lib1938.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1938(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1939.c b/tests/libtest/lib1939.c index 9985af5adc..b3d79fc68d 100644 --- a/tests/libtest/lib1939.c +++ b/tests/libtest/lib1939.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1939(const char *URL) { CURLM *multi; diff --git a/tests/libtest/lib1940.c b/tests/libtest/lib1940.c index 283128dc31..75b8f7818c 100644 --- a/tests/libtest/lib1940.c +++ b/tests/libtest/lib1940.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1940_write_cb(char *data, size_t n, size_t l, void *userp) { /* take care of the data here, ignored in this example */ diff --git a/tests/libtest/lib1945.c b/tests/libtest/lib1945.c index ee8e69f100..99044880cf 100644 --- a/tests/libtest/lib1945.c +++ b/tests/libtest/lib1945.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static void t1945_showem(CURL *curl, unsigned int type) { struct curl_header *header = NULL; diff --git a/tests/libtest/lib1947.c b/tests/libtest/lib1947.c index 19fbcb7af4..acbc260aa1 100644 --- a/tests/libtest/lib1947.c +++ b/tests/libtest/lib1947.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1947_write_cb(char *data, size_t n, size_t l, void *userp) { /* ignore the data */ diff --git a/tests/libtest/lib1955.c b/tests/libtest/lib1955.c index e47a52275e..3fe118269e 100644 --- a/tests/libtest/lib1955.c +++ b/tests/libtest/lib1955.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1955(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1956.c b/tests/libtest/lib1956.c index 0f1c72e3d2..a86a4c9e4c 100644 --- a/tests/libtest/lib1956.c +++ b/tests/libtest/lib1956.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1956(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1957.c b/tests/libtest/lib1957.c index 8eeed09b7c..c7864a150c 100644 --- a/tests/libtest/lib1957.c +++ b/tests/libtest/lib1957.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1957(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1958.c b/tests/libtest/lib1958.c index 7a94c76709..9a7f12f286 100644 --- a/tests/libtest/lib1958.c +++ b/tests/libtest/lib1958.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1958(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1959.c b/tests/libtest/lib1959.c index d718149772..6739cfe3ab 100644 --- a/tests/libtest/lib1959.c +++ b/tests/libtest/lib1959.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1959(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1960.c b/tests/libtest/lib1960.c index 152b1053f1..2dbdf5995f 100644 --- a/tests/libtest/lib1960.c +++ b/tests/libtest/lib1960.c @@ -32,8 +32,6 @@ #include #endif -#include "memdebug.h" - /* to prevent libcurl from closing our socket */ static int closesocket_cb(void *clientp, curl_socket_t item) { diff --git a/tests/libtest/lib1964.c b/tests/libtest/lib1964.c index cbad31dcc0..9536575ba8 100644 --- a/tests/libtest/lib1964.c +++ b/tests/libtest/lib1964.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1964(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1970.c b/tests/libtest/lib1970.c index 5ba51f6a58..fa110462c2 100644 --- a/tests/libtest/lib1970.c +++ b/tests/libtest/lib1970.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1970(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1971.c b/tests/libtest/lib1971.c index bc25226bde..982f06b286 100644 --- a/tests/libtest/lib1971.c +++ b/tests/libtest/lib1971.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1971_read_cb(char *ptr, size_t size, size_t nitems, void *userp) { (void)ptr; diff --git a/tests/libtest/lib1972.c b/tests/libtest/lib1972.c index ec9c9b0698..7931e866bf 100644 --- a/tests/libtest/lib1972.c +++ b/tests/libtest/lib1972.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1972(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1973.c b/tests/libtest/lib1973.c index e887e80c2e..2cc1c8ebfe 100644 --- a/tests/libtest/lib1973.c +++ b/tests/libtest/lib1973.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1973(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1974.c b/tests/libtest/lib1974.c index b2d0b59450..1534cfadee 100644 --- a/tests/libtest/lib1974.c +++ b/tests/libtest/lib1974.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1974(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib1975.c b/tests/libtest/lib1975.c index d6c05a1251..c5b6568a07 100644 --- a/tests/libtest/lib1975.c +++ b/tests/libtest/lib1975.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t1975_read_cb(char *ptr, size_t size, size_t nitems, void *userp) { (void)ptr; diff --git a/tests/libtest/lib1977.c b/tests/libtest/lib1977.c index dae8bcbae7..10412f66c0 100644 --- a/tests/libtest/lib1977.c +++ b/tests/libtest/lib1977.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1977(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib1978.c b/tests/libtest/lib1978.c index 113f06da8f..6c06e727dc 100644 --- a/tests/libtest/lib1978.c +++ b/tests/libtest/lib1978.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib1978(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib2023.c b/tests/libtest/lib2023.c index 8c181fa093..1475deb2d3 100644 --- a/tests/libtest/lib2023.c +++ b/tests/libtest/lib2023.c @@ -28,14 +28,12 @@ #include "first.h" -#include "memdebug.h" - static CURLcode send_request(CURL *curl, const char *url, int seq, long auth_scheme, const char *userpwd) { CURLcode res; size_t len = strlen(url) + 4 + 1; - char *full_url = malloc(len); + char *full_url = curlx_malloc(len); if(!full_url) { curl_mfprintf(stderr, "Not enough memory for full url\n"); return CURLE_OUT_OF_MEMORY; @@ -54,7 +52,7 @@ static CURLcode send_request(CURL *curl, const char *url, int seq, res = curl_easy_perform(curl); test_cleanup: - free(full_url); + curlx_free(full_url); return res; } diff --git a/tests/libtest/lib2032.c b/tests/libtest/lib2032.c index e0f9990f59..a733f34e6f 100644 --- a/tests/libtest/lib2032.c +++ b/tests/libtest/lib2032.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define MAX_EASY_HANDLES 3 static int ntlm_counter[MAX_EASY_HANDLES]; @@ -92,7 +90,7 @@ static CURLcode test_lib2032(const char *URL) /* libntlmconnect */ int num_handles = 0; enum HandleState state = ReadyForNewHandle; size_t urllen = strlen(URL) + 4 + 1; - char *full_url = malloc(urllen); + char *full_url = curlx_malloc(urllen); start_test_timing(); @@ -108,7 +106,7 @@ static CURLcode test_lib2032(const char *URL) /* libntlmconnect */ res_global_init(CURL_GLOBAL_ALL); if(res) { - free(full_url); + curlx_free(full_url); return res; } @@ -230,7 +228,7 @@ test_cleanup: curl_multi_cleanup(multi); curl_global_cleanup(); - free(full_url); + curlx_free(full_url); return res; } diff --git a/tests/libtest/lib2302.c b/tests/libtest/lib2302.c index 47276197bb..aa0be3d514 100644 --- a/tests/libtest/lib2302.c +++ b/tests/libtest/lib2302.c @@ -102,7 +102,7 @@ static CURLcode test_lib2302(const char *URL) global_init(CURL_GLOBAL_ALL); memset(&ws_data, 0, sizeof(ws_data)); - ws_data.buf = (char *)calloc(LIB2302_BUFSIZE, 1); + ws_data.buf = (char *)curlx_calloc(LIB2302_BUFSIZE, 1); if(ws_data.buf) { curl = curl_easy_init(); if(curl) { @@ -120,7 +120,7 @@ static CURLcode test_lib2302(const char *URL) curl_easy_cleanup(curl); flush_data(&ws_data); } - free(ws_data.buf); + curlx_free(ws_data.buf); } curl_global_cleanup(); return res; diff --git a/tests/libtest/lib2402.c b/tests/libtest/lib2402.c index 1695208716..58c1b6c431 100644 --- a/tests/libtest/lib2402.c +++ b/tests/libtest/lib2402.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib2402(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib2404.c b/tests/libtest/lib2404.c index 42d81d8d4a..93a3ef926f 100644 --- a/tests/libtest/lib2404.c +++ b/tests/libtest/lib2404.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib2404(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib2405.c b/tests/libtest/lib2405.c index 4f3c8015c6..97d0d5d231 100644 --- a/tests/libtest/lib2405.c +++ b/tests/libtest/lib2405.c @@ -39,8 +39,6 @@ #include "first.h" -#include "memdebug.h" - /* ---------------------------------------------------------------- */ #define test_check(expected_fds) \ diff --git a/tests/libtest/lib2502.c b/tests/libtest/lib2502.c index b9a2cabd79..4b5e0ef683 100644 --- a/tests/libtest/lib2502.c +++ b/tests/libtest/lib2502.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib2502(const char *URL) { diff --git a/tests/libtest/lib2700.c b/tests/libtest/lib2700.c index f509089645..1760d243ea 100644 --- a/tests/libtest/lib2700.c +++ b/tests/libtest/lib2700.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifndef CURL_DISABLE_WEBSOCKETS diff --git a/tests/libtest/lib3010.c b/tests/libtest/lib3010.c index 4595f4de35..0f805c2d6f 100644 --- a/tests/libtest/lib3010.c +++ b/tests/libtest/lib3010.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3010(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib3025.c b/tests/libtest/lib3025.c index b0056193b7..7d94c40626 100644 --- a/tests/libtest/lib3025.c +++ b/tests/libtest/lib3025.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3025(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib3027.c b/tests/libtest/lib3027.c index 5cd2bd757d..7a25c214bb 100644 --- a/tests/libtest/lib3027.c +++ b/tests/libtest/lib3027.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3027(const char *URL) { CURLcode ret = CURLE_OK; diff --git a/tests/libtest/lib3033.c b/tests/libtest/lib3033.c index b00bba9e74..428de8afc3 100644 --- a/tests/libtest/lib3033.c +++ b/tests/libtest/lib3033.c @@ -25,8 +25,6 @@ #include "testtrace.h" -#include "memdebug.h" - static CURLcode t3033_req_test(CURLM *multi, CURL *curl, const char *URL, int index) { diff --git a/tests/libtest/lib3100.c b/tests/libtest/lib3100.c index b661aa76ce..e9a2b4111c 100644 --- a/tests/libtest/lib3100.c +++ b/tests/libtest/lib3100.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3100(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib3101.c b/tests/libtest/lib3101.c index 3f5cbce17c..d95167f0ce 100644 --- a/tests/libtest/lib3101.c +++ b/tests/libtest/lib3101.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3101(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib3102.c b/tests/libtest/lib3102.c index 9cc87543dc..72da47551e 100644 --- a/tests/libtest/lib3102.c +++ b/tests/libtest/lib3102.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Verify correct order of certificates in the chain by comparing the * subject and issuer attributes of each certificate. diff --git a/tests/libtest/lib3103.c b/tests/libtest/lib3103.c index 5b25e1cd41..4e3a0d79fd 100644 --- a/tests/libtest/lib3103.c +++ b/tests/libtest/lib3103.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3103(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib3104.c b/tests/libtest/lib3104.c index dd1500ede5..278aa515b1 100644 --- a/tests/libtest/lib3104.c +++ b/tests/libtest/lib3104.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3104(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib3105.c b/tests/libtest/lib3105.c index 808fd98ca4..a3cbf28bb8 100644 --- a/tests/libtest/lib3105.c +++ b/tests/libtest/lib3105.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3105(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib3207.c b/tests/libtest/lib3207.c index 8ba88e4a66..7757643a26 100644 --- a/tests/libtest/lib3207.c +++ b/tests/libtest/lib3207.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #ifdef USE_THREADS_POSIX #include #endif @@ -48,7 +46,7 @@ static size_t write_memory_callback(char *contents, size_t size, /* append the data to contents */ size_t realsize = size * nmemb; struct Ctx *mem = (struct Ctx *)userp; - char *data = (char *)malloc(realsize + 1); + char *data = (char *)curlx_malloc(realsize + 1); struct curl_slist *item_append = NULL; if(!data) { curl_mprintf("not enough memory (malloc returned NULL)\n"); @@ -57,7 +55,7 @@ static size_t write_memory_callback(char *contents, size_t size, memcpy(data, contents, realsize); data[realsize] = '\0'; item_append = curl_slist_append(mem->contents, data); - free(data); + curlx_free(data); if(item_append) { mem->contents = item_append; } diff --git a/tests/libtest/lib3208.c b/tests/libtest/lib3208.c index 39585c1597..befa92e6d0 100644 --- a/tests/libtest/lib3208.c +++ b/tests/libtest/lib3208.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib3208(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib500.c b/tests/libtest/lib500.c index ff886a05ca..0d01b01026 100644 --- a/tests/libtest/lib500.c +++ b/tests/libtest/lib500.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static int testcounter; diff --git a/tests/libtest/lib501.c b/tests/libtest/lib501.c index d761c8a636..3dbed1cd4f 100644 --- a/tests/libtest/lib501.c +++ b/tests/libtest/lib501.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib501(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib502.c b/tests/libtest/lib502.c index c33783ea68..4e1fc14a97 100644 --- a/tests/libtest/lib502.c +++ b/tests/libtest/lib502.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib503.c b/tests/libtest/lib503.c index 34a6105bf7..48f0b671b9 100644 --- a/tests/libtest/lib503.c +++ b/tests/libtest/lib503.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Source code in here hugely as reported in bug report 651460 by * Christopher R. Palmer. diff --git a/tests/libtest/lib504.c b/tests/libtest/lib504.c index fa9338f262..996130c246 100644 --- a/tests/libtest/lib504.c +++ b/tests/libtest/lib504.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Source code in here hugely as reported in bug report 651464 by * Christopher R. Palmer. diff --git a/tests/libtest/lib505.c b/tests/libtest/lib505.c index 37cc1e0b3f..b28a01a9ce 100644 --- a/tests/libtest/lib505.c +++ b/tests/libtest/lib505.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * This example shows an FTP upload, with a rename of the file just after * a successful upload. diff --git a/tests/libtest/lib506.c b/tests/libtest/lib506.c index 928c33b13c..3d2a3556fd 100644 --- a/tests/libtest/lib506.c +++ b/tests/libtest/lib506.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" #define THREADS 2 diff --git a/tests/libtest/lib507.c b/tests/libtest/lib507.c index 9a306d39a6..0496099ce2 100644 --- a/tests/libtest/lib507.c +++ b/tests/libtest/lib507.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib507(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib508.c b/tests/libtest/lib508.c index a4c25b7918..6975051500 100644 --- a/tests/libtest/lib508.c +++ b/tests/libtest/lib508.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t508_WriteThis { const char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib509.c b/tests/libtest/lib509.c index a8be3eae52..b5a0c583e0 100644 --- a/tests/libtest/lib509.c +++ b/tests/libtest/lib509.c @@ -29,9 +29,8 @@ * libcurl and that it works unconditionally no matter how libcurl is built, * nothing more. * - * Do not include memdebug.h in this source file, and do not use directly - * memory related functions in this file except those used inside custom - * memory callbacks which should be calling 'the real thing'. + * Do not use directly memory related functions in this file except those used + * inside custom memory callbacks which should be calling 'the real thing'. */ static int seen; @@ -39,31 +38,40 @@ static int seen; static void *custom_calloc(size_t nmemb, size_t size) { seen++; - return (calloc)(nmemb, size); + /* !checksrc! disable BANNEDFUNC 1 */ + return calloc(nmemb, size); } static void *custom_malloc(size_t size) { seen++; - return (malloc)(size); + /* !checksrc! disable BANNEDFUNC 1 */ + return malloc(size); } static char *custom_strdup(const char *ptr) { seen++; - return (strdup)(ptr); +#ifdef _WIN32 + return _strdup(ptr); +#else + /* !checksrc! disable BANNEDFUNC 1 */ + return strdup(ptr); +#endif } static void *custom_realloc(void *ptr, size_t size) { seen++; - return (realloc)(ptr, size); + /* !checksrc! disable BANNEDFUNC 1 */ + return realloc(ptr, size); } static void custom_free(void *ptr) { seen++; - (free)(ptr); + /* !checksrc! disable BANNEDFUNC 1 */ + free(ptr); } @@ -95,10 +103,11 @@ static CURLcode test_lib509(const char *URL) return TEST_ERR_MAJOR_BAD; } - test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses strdup() */ + test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses curlx_strdup() */ asize = (int)sizeof(a); - str = curl_easy_escape(curl, (const char *)a, asize); /* uses realloc() */ + /* uses curlx_realloc() */ + str = curl_easy_escape(curl, (const char *)a, asize); if(seen) curl_mprintf("Callbacks were invoked!\n"); diff --git a/tests/libtest/lib510.c b/tests/libtest/lib510.c index da270c1c92..d2df0eaf20 100644 --- a/tests/libtest/lib510.c +++ b/tests/libtest/lib510.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t510_WriteThis { int counter; }; diff --git a/tests/libtest/lib511.c b/tests/libtest/lib511.c index 1db4093780..c4e78a1117 100644 --- a/tests/libtest/lib511.c +++ b/tests/libtest/lib511.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib511(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib512.c b/tests/libtest/lib512.c index 59a1cd7595..be7187542a 100644 --- a/tests/libtest/lib512.c +++ b/tests/libtest/lib512.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* Test case code based on source in a bug report filed by James Bursa on 28 Apr 2004 */ diff --git a/tests/libtest/lib513.c b/tests/libtest/lib513.c index 3d0afb1191..1458971007 100644 --- a/tests/libtest/lib513.c +++ b/tests/libtest/lib513.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static size_t t513_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { (void)ptr; diff --git a/tests/libtest/lib514.c b/tests/libtest/lib514.c index f47cdb321d..0ce96f5be8 100644 --- a/tests/libtest/lib514.c +++ b/tests/libtest/lib514.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib514(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib515.c b/tests/libtest/lib515.c index d9814525df..b0d3a65d50 100644 --- a/tests/libtest/lib515.c +++ b/tests/libtest/lib515.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib515(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib516.c b/tests/libtest/lib516.c index b7778a6a76..42b63c9d87 100644 --- a/tests/libtest/lib516.c +++ b/tests/libtest/lib516.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib516(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib517.c b/tests/libtest/lib517.c index 01d3ac4bad..843c5c03f0 100644 --- a/tests/libtest/lib517.c +++ b/tests/libtest/lib517.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib517(const char *URL) { struct dcheck { diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c index b8a9ec4a6a..d785857bb1 100644 --- a/tests/libtest/lib518.c +++ b/tests/libtest/lib518.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" #ifndef FD_SETSIZE #error "this test requires FD_SETSIZE" @@ -65,7 +64,7 @@ static void t518_close_file_descriptors(void) t518_num_open.rlim_cur++) if(t518_testfd[t518_num_open.rlim_cur] > 0) close(t518_testfd[t518_num_open.rlim_cur]); - free(t518_testfd); + curlx_free(t518_testfd); t518_testfd = NULL; } @@ -213,8 +212,8 @@ static int t518_test_rlimit(int keep_open) * avoid a low memory condition once the file descriptors are * open. System conditions that could make the test fail should * be addressed in the precheck phase. This chunk of memory shall - * be always free()ed before exiting the t518_test_rlimit() function so - * that it becomes available to the test. + * be always curlx_free()ed before exiting the t518_test_rlimit() + * function so that it becomes available to the test. */ for(nitems = i = 1; nitems <= i; i *= 2) @@ -225,7 +224,7 @@ static int t518_test_rlimit(int keep_open) t518_num_open.rlim_max = sizeof(*memchunk) * nitems; tutil_rlim2str(strbuff, sizeof(strbuff), t518_num_open.rlim_max); curl_mfprintf(stderr, "allocating memchunk %s byte array\n", strbuff); - memchunk = malloc(sizeof(*memchunk) * (size_t)nitems); + memchunk = curlx_malloc(sizeof(*memchunk) * (size_t)nitems); if(!memchunk) { curl_mfprintf(stderr, "memchunk, malloc() failed\n"); nitems /= 2; @@ -248,7 +247,7 @@ static int t518_test_rlimit(int keep_open) t518_num_open.rlim_max = NUM_OPEN; - /* verify that we do not overflow size_t in malloc() */ + /* verify that we do not overflow size_t in curlx_malloc() */ if((size_t)(t518_num_open.rlim_max) > ((size_t)-1) / sizeof(*t518_testfd)) { tutil_rlim2str(strbuff1, sizeof(strbuff1), t518_num_open.rlim_max); @@ -257,7 +256,7 @@ static int t518_test_rlimit(int keep_open) "file descriptors, would overflow size_t", strbuff1); t518_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t518_msgbuff); - free(memchunk); + curlx_free(memchunk); return -6; } @@ -266,12 +265,12 @@ static int t518_test_rlimit(int keep_open) tutil_rlim2str(strbuff, sizeof(strbuff), t518_num_open.rlim_max); curl_mfprintf(stderr, "allocating array for %s file descriptors\n", strbuff); - t518_testfd = malloc(sizeof(*t518_testfd) * - (size_t)(t518_num_open.rlim_max)); + t518_testfd = curlx_malloc(sizeof(*t518_testfd) * + (size_t)(t518_num_open.rlim_max)); if(!t518_testfd) { t518_store_errmsg("testfd, malloc() failed", errno); curl_mfprintf(stderr, "%s\n", t518_msgbuff); - free(memchunk); + curlx_free(memchunk); return -7; } @@ -294,9 +293,9 @@ 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); - free(t518_testfd); + curlx_free(t518_testfd); t518_testfd = NULL; - free(memchunk); + curlx_free(memchunk); return -8; } @@ -335,9 +334,9 @@ static int t518_test_rlimit(int keep_open) t518_testfd[t518_num_open.rlim_cur] >= 0; t518_num_open.rlim_cur++) close(t518_testfd[t518_num_open.rlim_cur]); - free(t518_testfd); + curlx_free(t518_testfd); t518_testfd = NULL; - free(memchunk); + curlx_free(memchunk); return -9; } } @@ -365,7 +364,7 @@ static int t518_test_rlimit(int keep_open) t518_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t518_msgbuff); t518_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -10; } @@ -380,7 +379,7 @@ static int t518_test_rlimit(int keep_open) t518_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t518_msgbuff); t518_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -11; } } @@ -405,14 +404,14 @@ static int t518_test_rlimit(int keep_open) "fopen fails with lots of fds open"); t518_store_errmsg(strbuff, 0); t518_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -12; } /* free the chunk of memory we were reserving so that it becomes available to the test */ - free(memchunk); + curlx_free(memchunk); /* close file descriptors unless instructed to keep them */ diff --git a/tests/libtest/lib519.c b/tests/libtest/lib519.c index 615e8aac8a..0d2f23e0d3 100644 --- a/tests/libtest/lib519.c +++ b/tests/libtest/lib519.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib519(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib520.c b/tests/libtest/lib520.c index 34f7c541e2..b3e67864e2 100644 --- a/tests/libtest/lib520.c +++ b/tests/libtest/lib520.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib520(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib521.c b/tests/libtest/lib521.c index acfec70381..0d2bacd16d 100644 --- a/tests/libtest/lib521.c +++ b/tests/libtest/lib521.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib521(const char *URL) { CURLcode res = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/lib523.c b/tests/libtest/lib523.c index 3b56ada894..60648a7da1 100644 --- a/tests/libtest/lib523.c +++ b/tests/libtest/lib523.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib523(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib524.c b/tests/libtest/lib524.c index e015e58637..5b7e01c087 100644 --- a/tests/libtest/lib524.c +++ b/tests/libtest/lib524.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib524(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib525.c b/tests/libtest/lib525.c index 4ca7ab7d65..abc75644ce 100644 --- a/tests/libtest/lib525.c +++ b/tests/libtest/lib525.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib525(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib526.c b/tests/libtest/lib526.c index 6f586c5a3e..a4d5ab6b1a 100644 --- a/tests/libtest/lib526.c +++ b/tests/libtest/lib526.c @@ -42,8 +42,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib526(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c index e7e86a32cc..429a4869f5 100644 --- a/tests/libtest/lib530.c +++ b/tests/libtest/lib530.c @@ -30,9 +30,6 @@ #include "first.h" -#include "memdebug.h" - - static struct t530_ctx { int socket_calls; int max_socket_calls; @@ -106,14 +103,15 @@ static int t530_addFd(struct t530_Sockets *sockets, curl_socket_t fd, * Allocate array storage when required. */ if(!sockets->sockets) { - sockets->sockets = malloc(sizeof(curl_socket_t) * 20U); + sockets->sockets = curlx_malloc(sizeof(curl_socket_t) * 20U); if(!sockets->sockets) return 1; sockets->max_count = 20; } else if(sockets->count + 1 > sockets->max_count) { - curl_socket_t *ptr = realloc(sockets->sockets, sizeof(curl_socket_t) * - (sockets->max_count + 20)); + curl_socket_t *ptr = curlx_realloc(sockets->sockets, + sizeof(curl_socket_t) * + (sockets->max_count + 20)); if(!ptr) /* cleanup in test_cleanup */ return 1; @@ -390,8 +388,8 @@ test_cleanup: curl_global_cleanup(); /* free local memory */ - free(sockets.read.sockets); - free(sockets.write.sockets); + curlx_free(sockets.read.sockets); + curlx_free(sockets.write.sockets); t530_msg("done"); return res; diff --git a/tests/libtest/lib533.c b/tests/libtest/lib533.c index 8f3b0f1474..b730960695 100644 --- a/tests/libtest/lib533.c +++ b/tests/libtest/lib533.c @@ -25,8 +25,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib533(const char *URL) { CURLcode res = CURLE_OK; diff --git a/tests/libtest/lib536.c b/tests/libtest/lib536.c index c0107ed9cb..4810aba83f 100644 --- a/tests/libtest/lib536.c +++ b/tests/libtest/lib536.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static void proxystat(CURL *curl) { long wasproxy; diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c index 02d4a89b26..8027a09c02 100644 --- a/tests/libtest/lib537.c +++ b/tests/libtest/lib537.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" #if !defined(HAVE_POLL) && !defined(USE_WINSOCK) && !defined(FD_SETSIZE) #error "this test requires FD_SETSIZE" @@ -62,7 +61,7 @@ static void t537_close_file_descriptors(void) t537_num_open.rlim_cur++) if(t537_testfd[t537_num_open.rlim_cur] > 0) close(t537_testfd[t537_num_open.rlim_cur]); - free(t537_testfd); + curlx_free(t537_testfd); t537_testfd = NULL; } @@ -193,8 +192,8 @@ static int t537_test_rlimit(int keep_open) * avoid a low memory condition once the file descriptors are * open. System conditions that could make the test fail should * be addressed in the precheck phase. This chunk of memory shall - * be always free()ed before exiting the t537_test_rlimit() function so - * that it becomes available to the test. + * be always curlx_free()ed before exiting the t537_test_rlimit() + * function so that it becomes available to the test. */ for(nitems = i = 1; nitems <= i; i *= 2) @@ -205,7 +204,7 @@ static int t537_test_rlimit(int keep_open) t537_num_open.rlim_max = sizeof(*memchunk) * nitems; tutil_rlim2str(strbuff, sizeof(strbuff), t537_num_open.rlim_max); curl_mfprintf(stderr, "allocating memchunk %s byte array\n", strbuff); - memchunk = malloc(sizeof(*memchunk) * (size_t)nitems); + memchunk = curlx_malloc(sizeof(*memchunk) * (size_t)nitems); if(!memchunk) { curl_mfprintf(stderr, "memchunk, malloc() failed\n"); nitems /= 2; @@ -243,7 +242,7 @@ static int t537_test_rlimit(int keep_open) t537_num_open.rlim_max = nitems; } - /* verify that we do not overflow size_t in malloc() */ + /* verify that we do not overflow size_t in curlx_malloc() */ if((size_t)(t537_num_open.rlim_max) > ((size_t)-1) / sizeof(*t537_testfd)) { tutil_rlim2str(strbuff1, sizeof(strbuff1), t537_num_open.rlim_max); @@ -252,7 +251,7 @@ static int t537_test_rlimit(int keep_open) "file descriptors, would overflow size_t", strbuff1); t537_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t537_msgbuff); - free(memchunk); + curlx_free(memchunk); return -5; } @@ -263,8 +262,8 @@ static int t537_test_rlimit(int keep_open) curl_mfprintf(stderr, "allocating array for %s file descriptors\n", strbuff); - t537_testfd = malloc(sizeof(*t537_testfd) * - (size_t)(t537_num_open.rlim_max)); + t537_testfd = curlx_malloc(sizeof(*t537_testfd) * + (size_t)(t537_num_open.rlim_max)); if(!t537_testfd) { curl_mfprintf(stderr, "testfd, malloc() failed\n"); t537_num_open.rlim_max /= 2; @@ -273,7 +272,7 @@ static int t537_test_rlimit(int keep_open) if(!t537_testfd) { t537_store_errmsg("testfd, malloc() failed", errno); curl_mfprintf(stderr, "%s\n", t537_msgbuff); - free(memchunk); + curlx_free(memchunk); return -6; } @@ -296,9 +295,9 @@ 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); - free(t537_testfd); + curlx_free(t537_testfd); t537_testfd = NULL; - free(memchunk); + curlx_free(memchunk); return -7; } @@ -345,8 +344,9 @@ static int t537_test_rlimit(int keep_open) /* we do not care if we cannot shrink it */ - tmpfd = realloc(t537_testfd, - sizeof(*t537_testfd) * (size_t)(t537_num_open.rlim_max)); + tmpfd = curlx_realloc(t537_testfd, + sizeof(*t537_testfd) * + (size_t)(t537_num_open.rlim_max)); if(tmpfd) { t537_testfd = tmpfd; tmpfd = NULL; @@ -379,7 +379,7 @@ static int t537_test_rlimit(int keep_open) t537_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t537_msgbuff); t537_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -8; } @@ -394,7 +394,7 @@ static int t537_test_rlimit(int keep_open) t537_store_errmsg(strbuff, 0); curl_mfprintf(stderr, "%s\n", t537_msgbuff); t537_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -9; } } @@ -419,14 +419,14 @@ static int t537_test_rlimit(int keep_open) "fopen fails with lots of fds open"); t537_store_errmsg(strbuff, 0); t537_close_file_descriptors(); - free(memchunk); + curlx_free(memchunk); return -10; } /* free the chunk of memory we were reserving so that it becomes available to the test */ - free(memchunk); + curlx_free(memchunk); /* close file descriptors unless instructed to keep them */ diff --git a/tests/libtest/lib539.c b/tests/libtest/lib539.c index e4e26c204a..1e6c0fb0ef 100644 --- a/tests/libtest/lib539.c +++ b/tests/libtest/lib539.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib539(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c index 55d5adad07..5e8890d984 100644 --- a/tests/libtest/lib540.c +++ b/tests/libtest/lib540.c @@ -32,8 +32,6 @@ #include "first.h" -#include "memdebug.h" - static CURL *t540_curl[2]; static CURLcode init(int num, CURLM *multi, const char *url, diff --git a/tests/libtest/lib541.c b/tests/libtest/lib541.c index ebab472456..891c2de525 100644 --- a/tests/libtest/lib541.c +++ b/tests/libtest/lib541.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Two FTP uploads, the second with no content sent. */ diff --git a/tests/libtest/lib542.c b/tests/libtest/lib542.c index b29a2733ff..d6689517c7 100644 --- a/tests/libtest/lib542.c +++ b/tests/libtest/lib542.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * FTP get with NOBODY but no HEADER */ diff --git a/tests/libtest/lib543.c b/tests/libtest/lib543.c index 579a71a611..9938d269ad 100644 --- a/tests/libtest/lib543.c +++ b/tests/libtest/lib543.c @@ -25,8 +25,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib543(const char *URL) { static const unsigned char a[] = { diff --git a/tests/libtest/lib544.c b/tests/libtest/lib544.c index d0ed914051..0d72af3042 100644 --- a/tests/libtest/lib544.c +++ b/tests/libtest/lib544.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib544(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib547.c b/tests/libtest/lib547.c index 9184d933a8..8f51fef088 100644 --- a/tests/libtest/lib547.c +++ b/tests/libtest/lib547.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - static const char t547_uploadthis[] = "this is the blurb we want to upload\n"; #define T547_DATALEN (sizeof(t547_uploadthis)-1) diff --git a/tests/libtest/lib549.c b/tests/libtest/lib549.c index 4eaacf5868..2793f92bcb 100644 --- a/tests/libtest/lib549.c +++ b/tests/libtest/lib549.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib549(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib552.c b/tests/libtest/lib552.c index 3d5b09c1ec..403ad6fec1 100644 --- a/tests/libtest/lib552.c +++ b/tests/libtest/lib552.c @@ -28,7 +28,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static size_t current_offset = 0; static char databuf[70000]; /* MUST be more than 64k OR diff --git a/tests/libtest/lib553.c b/tests/libtest/lib553.c index 0d44573131..4bc2568a46 100644 --- a/tests/libtest/lib553.c +++ b/tests/libtest/lib553.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - #define POSTLEN 40960 static size_t myreadfunc(char *ptr, size_t size, size_t nmemb, void *stream) diff --git a/tests/libtest/lib554.c b/tests/libtest/lib554.c index 230da065a1..dd8c690ddb 100644 --- a/tests/libtest/lib554.c +++ b/tests/libtest/lib554.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t554_WriteThis { const char *readptr; size_t sizeleft; diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c index 19e0480e2a..005fefe72f 100644 --- a/tests/libtest/lib555.c +++ b/tests/libtest/lib555.c @@ -32,8 +32,6 @@ #include "first.h" -#include "memdebug.h" - static const char t555_uploadthis[] = "this is the blurb we want to upload\n"; #define T555_DATALEN (sizeof(t555_uploadthis)-1) diff --git a/tests/libtest/lib556.c b/tests/libtest/lib556.c index daf92fe1e6..cdf9ebe941 100644 --- a/tests/libtest/lib556.c +++ b/tests/libtest/lib556.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib556(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index 38d93a687e..fa1ee2fa2f 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -33,8 +33,6 @@ # include /* for setlocale() */ #endif -#include "memdebug.h" - #if defined(CURL_GNUC_DIAG) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat" diff --git a/tests/libtest/lib558.c b/tests/libtest/lib558.c index c82b6ee969..94dd7f57b8 100644 --- a/tests/libtest/lib558.c +++ b/tests/libtest/lib558.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib558(const char *URL) { unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, @@ -40,7 +38,7 @@ static CURLcode test_lib558(const char *URL) return TEST_ERR_MAJOR_BAD; } - ptr = malloc(558); + ptr = curlx_malloc(558); Curl_safefree(ptr); asize = (int)sizeof(a); diff --git a/tests/libtest/lib559.c b/tests/libtest/lib559.c index 36a5575126..bf9cd86e63 100644 --- a/tests/libtest/lib559.c +++ b/tests/libtest/lib559.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib559(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib560.c b/tests/libtest/lib560.c index 45f137aabe..fc156f43d7 100644 --- a/tests/libtest/lib560.c +++ b/tests/libtest/lib560.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Simply download an HTTPS file! * diff --git a/tests/libtest/lib562.c b/tests/libtest/lib562.c index 3f2c912c91..fbe2560147 100644 --- a/tests/libtest/lib562.c +++ b/tests/libtest/lib562.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * From "KNOWN_BUGS" April 2009: diff --git a/tests/libtest/lib564.c b/tests/libtest/lib564.c index b105fc710e..56acfe40f7 100644 --- a/tests/libtest/lib564.c +++ b/tests/libtest/lib564.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" static CURLcode test_lib564(const char *URL) { diff --git a/tests/libtest/lib566.c b/tests/libtest/lib566.c index 79f48f235b..89adbdbd9c 100644 --- a/tests/libtest/lib566.c +++ b/tests/libtest/lib566.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib566(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib567.c b/tests/libtest/lib567.c index a11a6c31f0..95b66f102c 100644 --- a/tests/libtest/lib567.c +++ b/tests/libtest/lib567.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Test a simple OPTIONS request with a custom header */ diff --git a/tests/libtest/lib568.c b/tests/libtest/lib568.c index 5465ca0c8b..260061f519 100644 --- a/tests/libtest/lib568.c +++ b/tests/libtest/lib568.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" /* * Test the Client->Server ANNOUNCE functionality (PUT style) diff --git a/tests/libtest/lib569.c b/tests/libtest/lib569.c index 1c44153d00..77e0471e5f 100644 --- a/tests/libtest/lib569.c +++ b/tests/libtest/lib569.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" /* * Test Session ID capture diff --git a/tests/libtest/lib570.c b/tests/libtest/lib570.c index 300881efa7..f5ada6770b 100644 --- a/tests/libtest/lib570.c +++ b/tests/libtest/lib570.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" static CURLcode test_lib570(const char *URL) { diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c index 509557f0f5..678141b1c5 100644 --- a/tests/libtest/lib571.c +++ b/tests/libtest/lib571.c @@ -34,7 +34,6 @@ #endif #include "testutil.h" -#include "memdebug.h" #define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1]))) diff --git a/tests/libtest/lib572.c b/tests/libtest/lib572.c index 2865372f5f..4e20cb3da5 100644 --- a/tests/libtest/lib572.c +++ b/tests/libtest/lib572.c @@ -24,7 +24,6 @@ #include "first.h" #include "testutil.h" -#include "memdebug.h" /* * Test GET_PARAMETER: PUT, HEARTBEAT, and POST diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index 38612df7b5..ed00bbb042 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" /* * Get a single URL without select(). diff --git a/tests/libtest/lib574.c b/tests/libtest/lib574.c index e82be6c0d6..f74371e973 100644 --- a/tests/libtest/lib574.c +++ b/tests/libtest/lib574.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static int new_fnmatch(void *ptr, const char *pattern, const char *string) { diff --git a/tests/libtest/lib575.c b/tests/libtest/lib575.c index 36efe6ef5a..4709708a52 100644 --- a/tests/libtest/lib575.c +++ b/tests/libtest/lib575.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* 3x download! * 1. normal * 2. dup handle diff --git a/tests/libtest/lib576.c b/tests/libtest/lib576.c index 11c0f76d13..7ee7bc9525 100644 --- a/tests/libtest/lib576.c +++ b/tests/libtest/lib576.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct chunk_data { int remains; int print_content; diff --git a/tests/libtest/lib578.c b/tests/libtest/lib578.c index b6be1600f4..799821123d 100644 --- a/tests/libtest/lib578.c +++ b/tests/libtest/lib578.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */ static char t578_testdata[] = "this is a short string.\n"; diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index 9e626c1300..aaa81baede 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t579_WriteThis { int counter; }; diff --git a/tests/libtest/lib582.c b/tests/libtest/lib582.c index 4318096e1f..e99d5febdf 100644 --- a/tests/libtest/lib582.c +++ b/tests/libtest/lib582.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t582_Sockets { curl_socket_t *sockets; int count; /* number of sockets actually stored in array */ @@ -72,7 +70,7 @@ static void t582_addFd(struct t582_Sockets *sockets, curl_socket_t fd, * Allocate array storage when required. */ if(!sockets->sockets) { - sockets->sockets = malloc(sizeof(curl_socket_t) * 20U); + sockets->sockets = curlx_malloc(sizeof(curl_socket_t) * 20U); if(!sockets->sockets) return; sockets->max_count = 20; @@ -359,8 +357,8 @@ test_cleanup: curlx_fclose(hd_src); /* free local memory */ - free(sockets.read.sockets); - free(sockets.write.sockets); + curlx_free(sockets.read.sockets); + curlx_free(sockets.write.sockets); return res; } diff --git a/tests/libtest/lib583.c b/tests/libtest/lib583.c index 510c5a3bdc..8f29e310c7 100644 --- a/tests/libtest/lib583.c +++ b/tests/libtest/lib583.c @@ -28,8 +28,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib583(const char *URL) { int stillRunning; diff --git a/tests/libtest/lib586.c b/tests/libtest/lib586.c index dac6751b35..d0671b18fe 100644 --- a/tests/libtest/lib586.c +++ b/tests/libtest/lib586.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define THREADS 2 /* struct containing data of a thread */ diff --git a/tests/libtest/lib589.c b/tests/libtest/lib589.c index 9b912ab037..46b2a22a05 100644 --- a/tests/libtest/lib589.c +++ b/tests/libtest/lib589.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib589(const char *URL) { CURL *curl; diff --git a/tests/libtest/lib590.c b/tests/libtest/lib590.c index c804f995de..bba31e9da4 100644 --- a/tests/libtest/lib590.c +++ b/tests/libtest/lib590.c @@ -37,8 +37,6 @@ - Start the request */ -#include "memdebug.h" - static CURLcode test_lib590(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib591.c b/tests/libtest/lib591.c index c30bde5e8b..521cbb7503 100644 --- a/tests/libtest/lib591.c +++ b/tests/libtest/lib591.c @@ -25,8 +25,6 @@ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib591(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib597.c b/tests/libtest/lib597.c index e82d061a22..38e60c0844 100644 --- a/tests/libtest/lib597.c +++ b/tests/libtest/lib597.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Test case for below scenario: * - Connect to an FTP server using CONNECT_ONLY option diff --git a/tests/libtest/lib598.c b/tests/libtest/lib598.c index 56330c4a24..b42743845d 100644 --- a/tests/libtest/lib598.c +++ b/tests/libtest/lib598.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib598(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib599.c b/tests/libtest/lib599.c index 199ef90dbf..a216aa13a3 100644 --- a/tests/libtest/lib599.c +++ b/tests/libtest/lib599.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static int t599_progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c index d74d7ea9ee..52ea1eb664 100644 --- a/tests/libtest/lib643.c +++ b/tests/libtest/lib643.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t643_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib650.c b/tests/libtest/lib650.c index 069e94f8e5..4aa6ea9d8b 100644 --- a/tests/libtest/lib650.c +++ b/tests/libtest/lib650.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* This test attempts to use all form API features that are not * used elsewhere. */ diff --git a/tests/libtest/lib651.c b/tests/libtest/lib651.c index 05e9e381da..7d1d28563f 100644 --- a/tests/libtest/lib651.c +++ b/tests/libtest/lib651.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib651(const char *URL) { static char testbuf[17000]; /* more than 16K */ diff --git a/tests/libtest/lib652.c b/tests/libtest/lib652.c index dcbc5a3ab3..4fae340042 100644 --- a/tests/libtest/lib652.c +++ b/tests/libtest/lib652.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib652(const char *URL) { static char testbuf[17000]; /* more than 16K */ diff --git a/tests/libtest/lib653.c b/tests/libtest/lib653.c index 21948a5720..8447706958 100644 --- a/tests/libtest/lib653.c +++ b/tests/libtest/lib653.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib653(const char *URL) { CURL *curl = NULL; diff --git a/tests/libtest/lib654.c b/tests/libtest/lib654.c index 5b2236ebb0..1d93798d7c 100644 --- a/tests/libtest/lib654.c +++ b/tests/libtest/lib654.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t654_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib655.c b/tests/libtest/lib655.c index a213a1c493..3a8e0df434 100644 --- a/tests/libtest/lib655.c +++ b/tests/libtest/lib655.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static const char *TEST_DATA_STRING = "Test data"; static int cb_count = 0; diff --git a/tests/libtest/lib658.c b/tests/libtest/lib658.c index 4f0f867d65..edcb263338 100644 --- a/tests/libtest/lib658.c +++ b/tests/libtest/lib658.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib659.c b/tests/libtest/lib659.c index 84c3ecc8cd..5071e7fa26 100644 --- a/tests/libtest/lib659.c +++ b/tests/libtest/lib659.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib661.c b/tests/libtest/lib661.c index 10a4ab99ce..7cf6d09133 100644 --- a/tests/libtest/lib661.c +++ b/tests/libtest/lib661.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib661(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib666.c b/tests/libtest/lib666.c index cff244dafb..f47bacb9a8 100644 --- a/tests/libtest/lib666.c +++ b/tests/libtest/lib666.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib666(const char *URL) { static char testbuf[17000]; /* more than 16K */ diff --git a/tests/libtest/lib667.c b/tests/libtest/lib667.c index 2827d00511..1bd612f377 100644 --- a/tests/libtest/lib667.c +++ b/tests/libtest/lib667.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t667_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib668.c b/tests/libtest/lib668.c index 488f862152..5011391736 100644 --- a/tests/libtest/lib668.c +++ b/tests/libtest/lib668.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - struct t668_WriteThis { const char *readptr; curl_off_t sizeleft; diff --git a/tests/libtest/lib670.c b/tests/libtest/lib670.c index b30d097f68..e97b04319e 100644 --- a/tests/libtest/lib670.c +++ b/tests/libtest/lib670.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - #define PAUSE_TIME 5 struct t670_ReadThis { diff --git a/tests/libtest/lib674.c b/tests/libtest/lib674.c index 668ecdf32d..c84d1af05d 100644 --- a/tests/libtest/lib674.c +++ b/tests/libtest/lib674.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib676.c b/tests/libtest/lib676.c index 63437523df..17494b73e7 100644 --- a/tests/libtest/lib676.c +++ b/tests/libtest/lib676.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib676(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib677.c b/tests/libtest/lib677.c index 526e1706c3..089202b5c5 100644 --- a/tests/libtest/lib677.c +++ b/tests/libtest/lib677.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib677(const char *URL) { static const char testcmd[] = "A1 IDLE\r\n"; diff --git a/tests/libtest/lib678.c b/tests/libtest/lib678.c index 2a2e21321f..ed8731d20d 100644 --- a/tests/libtest/lib678.c +++ b/tests/libtest/lib678.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static int loadfile(const char *filename, void **filedata, size_t *filesize) { size_t datasize = 0; @@ -44,13 +42,13 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize) if(continue_reading) continue_reading = fseek(fInCert, 0, SEEK_SET) == 0; if(continue_reading) - data = malloc(datasize + 1); + data = curlx_malloc(datasize + 1); if((!data) || ((int)fread(data, datasize, 1, fInCert) != 1)) continue_reading = FALSE; curlx_fclose(fInCert); if(!continue_reading) { - free(data); + curlx_free(data); datasize = 0; data = NULL; } @@ -86,7 +84,7 @@ static CURLcode test_cert_blob(const char *url, const char *cafile) blob.len = certsize; blob.flags = CURL_BLOB_COPY; curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &blob); - free(certdata); + curlx_free(certdata); code = curl_easy_perform(curl); } curl_easy_cleanup(curl); diff --git a/tests/libtest/lib694.c b/tests/libtest/lib694.c index 5b477ecebd..25db2694c6 100644 --- a/tests/libtest/lib694.c +++ b/tests/libtest/lib694.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - static CURLcode test_lib694(const char *URL) { CURLcode res; diff --git a/tests/libtest/lib695.c b/tests/libtest/lib695.c index 325897c357..1177a529fd 100644 --- a/tests/libtest/lib695.c +++ b/tests/libtest/lib695.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* write callback that does nothing */ static size_t write_it(char *ptr, size_t size, size_t nmemb, void *userdata) { diff --git a/tests/libtest/lib751.c b/tests/libtest/lib751.c index 42c1aeb117..898ba8d7ef 100644 --- a/tests/libtest/lib751.c +++ b/tests/libtest/lib751.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* * Get a single URL without select(). */ diff --git a/tests/libtest/lib753.c b/tests/libtest/lib753.c index 19194c4646..f01fa3f5c8 100644 --- a/tests/libtest/lib753.c +++ b/tests/libtest/lib753.c @@ -24,7 +24,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" struct t753_transfer_status { CURL *curl; diff --git a/tests/libtest/lib757.c b/tests/libtest/lib757.c index 632818f946..f3a1e0fdb4 100644 --- a/tests/libtest/lib757.c +++ b/tests/libtest/lib757.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "memdebug.h" - /* write callback that does nothing */ static size_t write_757(char *ptr, size_t size, size_t nmemb, void *userdata) { diff --git a/tests/libtest/lib758.c b/tests/libtest/lib758.c index ab6ce481b7..bc6a490d3d 100644 --- a/tests/libtest/lib758.c +++ b/tests/libtest/lib758.c @@ -31,7 +31,6 @@ #include "first.h" #include "testtrace.h" -#include "memdebug.h" #ifdef USE_OPENSSL @@ -121,14 +120,15 @@ static int t758_addFd(struct t758_Sockets *sockets, curl_socket_t fd, * Allocate array storage when required. */ if(!sockets->sockets) { - sockets->sockets = malloc(sizeof(curl_socket_t) * 20U); + sockets->sockets = curlx_malloc(sizeof(curl_socket_t) * 20U); if(!sockets->sockets) return 1; sockets->max_count = 20; } else if(sockets->count + 1 > sockets->max_count) { - curl_socket_t *ptr = realloc(sockets->sockets, sizeof(curl_socket_t) * - (sockets->max_count + 20)); + curl_socket_t *ptr = curlx_realloc(sockets->sockets, + sizeof(curl_socket_t) * + (sockets->max_count + 20)); if(!ptr) /* cleanup in test_cleanup */ return 1; @@ -487,8 +487,8 @@ test_cleanup: curl_global_cleanup(); /* free local memory */ - free(sockets.read.sockets); - free(sockets.write.sockets); + curlx_free(sockets.read.sockets); + curlx_free(sockets.write.sockets); t758_msg("done"); return res; diff --git a/tests/libtest/lib766.c b/tests/libtest/lib766.c index 53f1dd97b5..bba08e263b 100644 --- a/tests/libtest/lib766.c +++ b/tests/libtest/lib766.c @@ -24,8 +24,6 @@ #include "first.h" -#include "memdebug.h" - static int sockopt_766(void *clientp, curl_socket_t curlfd, curlsocktype purpose) diff --git a/tests/libtest/memptr.c b/tests/libtest/memptr.c index 64e9fd7f8a..400e72c41a 100644 --- a/tests/libtest/memptr.c +++ b/tests/libtest/memptr.c @@ -23,8 +23,6 @@ ***************************************************************************/ #include "first.h" -#include "curl_memory.h" - #ifndef CURL_STATICLIB #if defined(_MSC_VER) && defined(_DLL) diff --git a/tests/libtest/mk-lib1521.pl b/tests/libtest/mk-lib1521.pl index 156422eccc..bfb0e590e7 100755 --- a/tests/libtest/mk-lib1521.pl +++ b/tests/libtest/mk-lib1521.pl @@ -206,7 +206,6 @@ print $fh <
, 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 -# -########################################################################### -# -# This script scans C source files. If they seem to use memory functions, -# it also makes sure that it #includes the correct two header files! -# -# You can also mark a C source as fine by using 'mem-include-scan' anywhere in -# it. -# - -use strict; -use warnings; - -my $dir = $ARGV[0] || die "specify directory!"; - -sub scanfile { - my ($file) = @_; - my $memfunc; - my $memdebug; - my $curlmem; - - print STDERR "checking $file...\n"; - - open(my $f, "<", "$file"); - while(<$f>) { - if($_ =~ /\W(free|alloc|strdup)\(/) { - $memfunc++; - } - elsif($_ =~ /^ *# *include \"memdebug.h\"/) { - $memdebug++; - } - elsif($_ =~ /^ *# *include \"curl_memory.h\"/) { - $curlmem++; - } - elsif($_ =~ /mem-include-scan/) { - # free pass - close($f); - return 0; - } - if($memfunc && $memdebug && $curlmem) { - last; - } - } - close($f); - - - if($memfunc) { - if($memdebug && $curlmem) { - return 0; - } - else { - if(!$memdebug) { - print STDERR "$file does not include \"memdebug.h\"!\n"; - } - if(!$curlmem) { - print STDERR "$file does not include \"curl_memory.h\"!\n"; - } - return 1; - } - } - return 0; -} - -opendir(my $dh, $dir) || die "cannot opendir $dir: $!"; -my @cfiles = grep { /\.c\z/ && -f "$dir/$_" } readdir($dh); -closedir $dh; - -my $errs; -for(@cfiles) { - $errs += scanfile("$dir/$_"); -} - -if($errs) { - print STDERR "----\n$errs errors detected!\n"; - exit 2; -} diff --git a/tests/tunit/tool1394.c b/tests/tunit/tool1394.c index 71be2c87c4..9d97dbb0de 100644 --- a/tests/tunit/tool1394.c +++ b/tests/tunit/tool1394.c @@ -25,8 +25,6 @@ #include "tool_getparam.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode test_tool1394(const char *arg) { UNITTEST_BEGIN_SIMPLE @@ -120,9 +118,9 @@ static CURLcode test_tool1394(const char *arg) } } if(certname) - free(certname); + curlx_free(certname); if(passphrase) - free(passphrase); + curlx_free(passphrase); } UNITTEST_END_SIMPLE diff --git a/tests/tunit/tool1604.c b/tests/tunit/tool1604.c index 3b6f006e7c..dcfee4cbac 100644 --- a/tests/tunit/tool1604.c +++ b/tests/tunit/tool1604.c @@ -26,12 +26,10 @@ #include "tool_cfgable.h" #include "tool_doswin.h" -#include "memdebug.h" /* LAST include file */ - #if defined(_WIN32) || defined(MSDOS) static char *getflagstr(int flags) { - char *buf = malloc(256); + char *buf = curlx_malloc(256); if(buf) { curl_msnprintf(buf, 256, "%s,%s", ((flags & SANITIZE_ALLOW_PATH) ? @@ -44,7 +42,7 @@ static char *getflagstr(int flags) static char *getcurlcodestr(int cc) { - char *buf = malloc(256); + char *buf = curlx_malloc(256); if(buf) { curl_msnprintf(buf, 256, "%s (%d)", (cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" : @@ -212,7 +210,7 @@ static CURLcode test_tool1604(const char *arg) ((!output && !data[i].expected_output) || (output && data[i].expected_output && !strcmp(output, data[i].expected_output)))) { /* OK */ - free(output); + curlx_free(output); continue; } @@ -240,10 +238,10 @@ static CURLcode test_tool1604(const char *arg) data[i].expected_output ? data[i].expected_output : "(null)", expected_ccstr); - free(output); - free(flagstr); - free(received_ccstr); - free(expected_ccstr); + curlx_free(output); + curlx_free(flagstr); + curlx_free(received_ccstr); + curlx_free(expected_ccstr); } /* END sanitize_file_name */ #else diff --git a/tests/tunit/tool1621.c b/tests/tunit/tool1621.c index bb709cf39d..ba9e280294 100644 --- a/tests/tunit/tool1621.c +++ b/tests/tunit/tool1621.c @@ -25,8 +25,6 @@ #include "tool_xattr.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode test_tool1621(const char *arg) { UNITTEST_BEGIN_SIMPLE diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index 911432a8c8..d56f7b09f7 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -25,7 +25,6 @@ #include "urldata.h" #include "url.h" /* for Curl_safefree */ -#include "memdebug.h" /* LAST include file */ struct etest { const char *input; diff --git a/tests/unit/unit1303.c b/tests/unit/unit1303.c index 03673c544e..9bed1ebff6 100644 --- a/tests/unit/unit1303.c +++ b/tests/unit/unit1303.c @@ -25,7 +25,6 @@ #include "urldata.h" #include "connect.h" -#include "memdebug.h" /* LAST include file */ static CURLcode t1303_setup(struct Curl_easy **easy) { diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c index 041ce42691..100f3f5828 100644 --- a/tests/unit/unit1304.c +++ b/tests/unit/unit1304.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "netrc.h" -#include "memdebug.h" /* LAST include file */ #ifndef CURL_DISABLE_NETRC @@ -120,8 +119,8 @@ static CURLcode test_unit1304(const char *arg) * Test for the first existing host in our netrc file * with login[0] != 0. */ - free(password); - free(login); + curlx_free(password); + curlx_free(login); password = NULL; login = NULL; Curl_netrc_init(&store); @@ -139,9 +138,9 @@ static CURLcode test_unit1304(const char *arg) * Test for the second existing host in our netrc file * with login[0] = 0. */ - free(password); + curlx_free(password); password = NULL; - free(login); + curlx_free(login); login = NULL; Curl_netrc_init(&store); result = Curl_parsenetrc(&store, @@ -158,9 +157,9 @@ static CURLcode test_unit1304(const char *arg) * Test for the second existing host in our netrc file * with login[0] != 0. */ - free(password); + curlx_free(password); password = NULL; - free(login); + curlx_free(login); login = NULL; Curl_netrc_init(&store); result = Curl_parsenetrc(&store, diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c index e95e299453..404d90bec9 100644 --- a/tests/unit/unit1305.c +++ b/tests/unit/unit1305.c @@ -36,8 +36,6 @@ #include "hash.h" #include "hostip.h" -#include "memdebug.h" /* LAST include file */ - static struct Curl_dnscache hp; static char *data_key; static struct Curl_dns_entry *data_node; @@ -52,9 +50,9 @@ static void t1305_stop(void) { if(data_node) { Curl_freeaddrinfo(data_node->addr); - free(data_node); + curlx_free(data_node); } - free(data_key); + curlx_free(data_key); Curl_dnscache_destroy(&hp); } @@ -64,8 +62,9 @@ static struct Curl_addrinfo *fake_ai(void) static const char dummy[] = "dummy"; size_t namelen = sizeof(dummy); /* including the null-terminator */ - ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) + - namelen); + ai = curlx_calloc(1, + sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) + + namelen); if(!ai) return NULL; @@ -86,7 +85,7 @@ static CURLcode create_node(void) if(!data_key) return CURLE_OUT_OF_MEMORY; - data_node = calloc(1, sizeof(struct Curl_dns_entry)); + data_node = curlx_calloc(1, sizeof(struct Curl_dns_entry)); if(!data_node) return CURLE_OUT_OF_MEMORY; diff --git a/tests/unit/unit1330.c b/tests/unit/unit1330.c index bd7fc6e259..a98393b532 100644 --- a/tests/unit/unit1330.c +++ b/tests/unit/unit1330.c @@ -23,13 +23,11 @@ ***************************************************************************/ #include "unitcheck.h" -#include "memdebug.h" - static CURLcode test_unit1330(const char *arg) { UNITTEST_BEGIN_SIMPLE - char *ptr = malloc(1330); + char *ptr = curlx_malloc(1330); Curl_safefree(ptr); UNITTEST_END_SIMPLE diff --git a/tests/unit/unit1395.c b/tests/unit/unit1395.c index e6ac18f081..395f3e7707 100644 --- a/tests/unit/unit1395.c +++ b/tests/unit/unit1395.c @@ -22,7 +22,6 @@ * ***************************************************************************/ #include "unitcheck.h" -#include "memdebug.h" #include "unitprotos.h" static CURLcode test_unit1395(const char *arg) @@ -133,7 +132,7 @@ static CURLcode test_unit1395(const char *arg) } else curl_mfprintf(stderr, "Test %u: OK\n", i); - free(out); + curlx_free(out); } fail_if(fails, "output mismatched"); diff --git a/tests/unit/unit1602.c b/tests/unit/unit1602.c index e397bdb5ca..5841717691 100644 --- a/tests/unit/unit1602.c +++ b/tests/unit/unit1602.c @@ -25,12 +25,10 @@ #include "hash.h" -#include "memdebug.h" /* LAST include file */ - static void t1602_mydtor(void *p) { int *ptr = (int *)p; - free(ptr); + curlx_free(ptr); } static CURLcode t1602_setup(struct Curl_hash *hash) @@ -59,22 +57,22 @@ static CURLcode test_unit1602(const char *arg) int key = 20; int key2 = 25; - value = malloc(sizeof(int)); + value = curlx_malloc(sizeof(int)); abort_unless(value != NULL, "Out of memory"); *value = 199; nodep = Curl_hash_add(&hash, &key, klen, value); if(!nodep) - free(value); + curlx_free(value); abort_unless(nodep, "insertion into hash failed"); Curl_hash_clean(&hash); /* Attempt to add another key/value pair */ - value2 = malloc(sizeof(int)); + value2 = curlx_malloc(sizeof(int)); abort_unless(value2 != NULL, "Out of memory"); *value2 = 204; nodep = Curl_hash_add(&hash, &key2, klen, value2); if(!nodep) - free(value2); + curlx_free(value2); abort_unless(nodep, "insertion into hash failed"); UNITTEST_END(t1602_stop(&hash)) diff --git a/tests/unit/unit1603.c b/tests/unit/unit1603.c index b4ec152936..81db398cb1 100644 --- a/tests/unit/unit1603.c +++ b/tests/unit/unit1603.c @@ -25,8 +25,6 @@ #include "hash.h" -#include "memdebug.h" /* LAST include file */ - static const size_t slots = 3; static void t1603_mydtor(void *p) diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c index f60b5b58a1..233866da18 100644 --- a/tests/unit/unit1607.c +++ b/tests/unit/unit1607.c @@ -27,8 +27,6 @@ #include "connect.h" #include "curl_share.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1607_setup(void) { CURLcode res = CURLE_OK; @@ -135,7 +133,7 @@ static CURLcode test_unit1607(const char *arg) goto error; dns = Curl_hash_pick(&multi->dnscache.entries, entry_id, strlen(entry_id) + 1); - free(entry_id); + curlx_free(entry_id); entry_id = NULL; addr = dns ? dns->addr : NULL; diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c index 2a3098c6ef..bf912b99cd 100644 --- a/tests/unit/unit1609.c +++ b/tests/unit/unit1609.c @@ -27,8 +27,6 @@ #include "connect.h" #include "curl_share.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1609_setup(void) { CURLcode res = CURLE_OK; @@ -137,7 +135,7 @@ static CURLcode test_unit1609(const char *arg) dns = Curl_hash_pick(&multi->dnscache.entries, entry_id, strlen(entry_id) + 1); - free(entry_id); + curlx_free(entry_id); entry_id = NULL; addr = dns ? dns->addr : NULL; diff --git a/tests/unit/unit1616.c b/tests/unit/unit1616.c index 5d1e6f247e..d898444613 100644 --- a/tests/unit/unit1616.c +++ b/tests/unit/unit1616.c @@ -25,13 +25,11 @@ #include "uint-hash.h" -#include "memdebug.h" /* LAST include file */ - static void t1616_mydtor(unsigned int id, void *elem) { int *ptr = (int *)elem; (void)id; - free(ptr); + curlx_free(ptr); } static CURLcode t1616_setup(struct uint_hash *hash) @@ -58,12 +56,12 @@ static CURLcode test_unit1616(const char *arg) unsigned int key = 20; unsigned int key2 = 25; - value = malloc(sizeof(int)); + value = curlx_malloc(sizeof(int)); abort_unless(value != NULL, "Out of memory"); *value = 199; ok = Curl_uint32_hash_set(&hash, key, value); if(!ok) - free(value); + curlx_free(value); abort_unless(ok, "insertion into hash failed"); v = Curl_uint32_hash_get(&hash, key); abort_unless(v == value, "lookup present entry failed"); @@ -72,12 +70,12 @@ static CURLcode test_unit1616(const char *arg) Curl_uint32_hash_clear(&hash); /* Attempt to add another key/value pair */ - value2 = malloc(sizeof(int)); + value2 = curlx_malloc(sizeof(int)); abort_unless(value2 != NULL, "Out of memory"); *value2 = 204; ok = Curl_uint32_hash_set(&hash, key2, value2); if(!ok) - free(value2); + curlx_free(value2); abort_unless(ok, "insertion into hash failed"); v = Curl_uint32_hash_get(&hash, key2); abort_unless(v == value2, "lookup present entry failed"); diff --git a/tests/unit/unit1620.c b/tests/unit/unit1620.c index 4851602eaa..4c1674f5bd 100644 --- a/tests/unit/unit1620.c +++ b/tests/unit/unit1620.c @@ -26,8 +26,6 @@ #include "urldata.h" #include "url.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1620_setup(void) { CURLcode res = CURLE_OK; @@ -64,9 +62,9 @@ static void t1620_parse( "options should be equal to exp_options"); } - free(userstr); - free(passwdstr); - free(options); + curlx_free(userstr); + curlx_free(passwdstr); + curlx_free(options); } static CURLcode test_unit1620(const char *arg) diff --git a/tests/unit/unit1653.c b/tests/unit/unit1653.c index 8f6a5a51cc..7ea7e380a8 100644 --- a/tests/unit/unit1653.c +++ b/tests/unit/unit1653.c @@ -53,7 +53,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -67,7 +67,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15|"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15|"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -78,7 +78,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff;fea7:da15]:808"); + ipv6port = curlx_strdup("[fe80::250:56ff;fea7:da15]:808"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -95,7 +95,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%25eth3]:80"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -111,7 +111,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%25eth3]"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -123,7 +123,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]:81"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -139,7 +139,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15];81"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15];81"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -150,7 +150,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]80"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]80"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -163,7 +163,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15]:"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]:"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, TRUE); @@ -175,7 +175,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15!25eth3]:180"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15!25eth3]:180"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -191,7 +191,7 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80"); + ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%eth3]:80"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); @@ -204,14 +204,14 @@ static CURLcode test_unit1653(const char *arg) u = curl_url(); if(!u) goto fail; - ipv6port = strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaa:"); + ipv6port = curlx_strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaa:"); if(!ipv6port) goto fail; ret = parse_port(u, ipv6port, FALSE); fail_unless(ret == CURLUE_BAD_PORT_NUMBER, "parse_port did wrong"); fail: - free(ipv6port); + curlx_free(ipv6port); curl_url_cleanup(u); UNITTEST_END_SIMPLE diff --git a/tests/unit/unit1661.c b/tests/unit/unit1661.c index 6cc4485544..d9aa2a61f1 100644 --- a/tests/unit/unit1661.c +++ b/tests/unit/unit1661.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "bufref.h" -#include "memdebug.h" static int freecount = 0; @@ -31,7 +30,7 @@ static void test_free(void *p) { fail_unless(p, "pointer to free may not be NULL"); freecount++; - free(p); + curlx_free(p); } static CURLcode t1661_setup(struct bufref *bufref) @@ -68,7 +67,7 @@ static CURLcode test_unit1661(const char *arg) /** * testing Curl_bufref_set */ - buffer = malloc(13); + buffer = curlx_malloc(13); abort_unless(buffer, "Out of memory"); Curl_bufref_set(&bufref, buffer, 13, test_free); diff --git a/tests/unit/unit1663.c b/tests/unit/unit1663.c index 0d6fb4bbbe..e4431930a4 100644 --- a/tests/unit/unit1663.c +++ b/tests/unit/unit1663.c @@ -32,8 +32,6 @@ #include "cf-socket.h" -#include "memdebug.h" /* LAST include file */ - static CURLcode t1663_setup(void) { CURLcode res = CURLE_OK; @@ -67,9 +65,9 @@ static void t1663_parse( "host should be equal to exp_host"); } - free(dev); - free(iface); - free(host); + curlx_free(dev); + curlx_free(iface); + curlx_free(host); } static CURLcode test_unit1663(const char *arg) diff --git a/tests/unit/unit1664.c b/tests/unit/unit1664.c index 6903c70e92..a24a859e52 100644 --- a/tests/unit/unit1664.c +++ b/tests/unit/unit1664.c @@ -30,8 +30,6 @@ #include #endif -#include "memdebug.h" /* LAST include file */ - static CURLcode t1664_setup(void) { CURLcode res = CURLE_OK; diff --git a/tests/unit/unit2600.c b/tests/unit/unit2600.c index f2adc50edd..b69b675b3b 100644 --- a/tests/unit/unit2600.c +++ b/tests/unit/unit2600.c @@ -47,7 +47,6 @@ #include "multiif.h" #include "select.h" #include "curl_trc.h" -#include "memdebug.h" static CURLcode t2600_setup(CURL **easy) { @@ -126,7 +125,7 @@ static void cf_test_destroy(struct Curl_cfilter *cf, struct Curl_easy *data) #else (void)data; #endif - free(ctx); + curlx_free(ctx); cf->ctx = NULL; } @@ -193,7 +192,7 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf, (void)data; (void)conn; - ctx = calloc(1, sizeof(*ctx)); + ctx = curlx_calloc(1, sizeof(*ctx)); if(!ctx) { res = CURLE_OUT_OF_MEMORY; goto out; @@ -233,8 +232,8 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf, out: *pcf = (!res) ? cf : NULL; if(res) { - free(cf); - free(ctx); + curlx_free(cf); + curlx_free(ctx); } return res; } diff --git a/tests/unit/unit2604.c b/tests/unit/unit2604.c index 695b121007..fb05189714 100644 --- a/tests/unit/unit2604.c +++ b/tests/unit/unit2604.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "vssh/vssh.h" -#include "memdebug.h" static CURLcode test_unit2604(const char *arg) { @@ -79,7 +78,7 @@ static CURLcode test_unit2604(const char *arg) #pragma GCC diagnostic pop #endif - char *cp0 = calloc(1, too_long + 1); + char *cp0 = curlx_calloc(1, too_long + 1); fail_unless(cp0, "could not alloc too long value"); memset(cp0, 'a', too_long); @@ -108,7 +107,7 @@ static CURLcode test_unit2604(const char *arg) } } - free(cp0); + curlx_free(cp0); #endif diff --git a/tests/unit/unit2605.c b/tests/unit/unit2605.c index 71c37f32cf..49d0b0b000 100644 --- a/tests/unit/unit2605.c +++ b/tests/unit/unit2605.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "vssh/vssh.h" -#include "memdebug.h" static CURLcode test_unit2605(const char *arg) { diff --git a/tests/unit/unit3200.c b/tests/unit/unit3200.c index 0b3c876911..fe00da939d 100644 --- a/tests/unit/unit3200.c +++ b/tests/unit/unit3200.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "unitcheck.h" #include "curl_get_line.h" -#include "memdebug.h" static CURLcode test_unit3200(const char *arg) {