]> git.ipfire.org Git - thirdparty/curl.git/commit
build: stop overriding standard memory allocation functions
authorViktor Szakats <commit@vsz.me>
Wed, 8 Oct 2025 00:33:19 +0000 (02:33 +0200)
committerViktor Szakats <commit@vsz.me>
Fri, 28 Nov 2025 09:44:26 +0000 (10:44 +0100)
commit193cb00ce9b47e75d42157c650cc3de3fd96d35d
tree603980e9eae654bb119bf238bc211e1f676f145e
parentbfc3d131b6b5be7b7219dc016ff600f58e279c6c
build: stop overriding standard memory allocation functions

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

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

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

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

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

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

Follow-up to b12da22db1f11da51082977dc21a7edee7858911 #18866
Follow-up to db98daab05aec251bcb6615d2d38dfebec291736 #18844
Follow-up to 4deea9396bc7dd25c6362fa746a57bf309c74ada #18814
Follow-up to 9678ff5b1bfea1c847aee4f9edf023e8f01c9293 #18776
Follow-up to 10bac43b873fe45869e15b36aac1c1e5bc89b6e0 #18774
Follow-up to 20142f5d06f7120ba94cbcc25c998e8d81aec85b #18634
Follow-up to bf7375ecc50e857760b0d0a668c436e208a400bd #18503
Follow-up to 9863599d69b79d290928a89bf9160f4e4e023d4e #18502
Follow-up to 3bb5e58c105d7be450b667858d1b8e7ae3ded555 #17827

Closes #19626
471 files changed:
docs/examples/.checksrc
docs/internals/CHECKSRC.md
docs/internals/CODE_STYLE.md
lib/Makefile.inc
lib/altsvc.c
lib/amigaos.c
lib/asyn-ares.c
lib/asyn-base.c
lib/asyn-thrdd.c
lib/bufq.c
lib/bufref.c
lib/cf-h1-proxy.c
lib/cf-h2-proxy.c
lib/cf-haproxy.c
lib/cf-https-connect.c
lib/cf-ip-happy.c
lib/cf-socket.c
lib/cfilters.c
lib/conncache.c
lib/connect.c
lib/content_encoding.c
lib/cookie.c
lib/cshutdn.c
lib/curl_addrinfo.c
lib/curl_fnmatch.c
lib/curl_fopen.c
lib/curl_get_line.c
lib/curl_gssapi.c
lib/curl_mem_undef.h [deleted file]
lib/curl_memory.h [deleted file]
lib/curl_memrchr.c
lib/curl_ntlm_core.c
lib/curl_rtmp.c
lib/curl_sasl.c
lib/curl_setup.h
lib/curl_share.c
lib/curl_sspi.c
lib/curl_threads.c
lib/curl_trc.c
lib/curlx/base64.c
lib/curlx/dynbuf.c
lib/curlx/fopen.c
lib/curlx/multibyte.c
lib/curlx/multibyte.h
lib/curlx/strerr.c
lib/curlx/version_win32.c
lib/cw-out.c
lib/cw-pause.c
lib/dict.c
lib/dllmain.c
lib/doh.c
lib/dynhds.c
lib/easy.c
lib/escape.c
lib/fake_addrinfo.c
lib/file.c
lib/fileinfo.c
lib/formdata.c
lib/ftp.c
lib/ftplistparser.c
lib/getenv.c
lib/getinfo.c
lib/gopher.c
lib/hash.c
lib/headers.c
lib/hmac.c
lib/hostip.c
lib/hostip4.c
lib/hostip6.c
lib/hsts.c
lib/http.c
lib/http1.c
lib/http2.c
lib/http_aws_sigv4.c
lib/http_chunks.c
lib/http_digest.c
lib/http_negotiate.c
lib/http_ntlm.c
lib/http_proxy.c
lib/httpsrr.c
lib/idn.c
lib/if2ip.c
lib/imap.c
lib/ldap.c
lib/llist.c
lib/md4.c
lib/md5.c
lib/memdebug.c
lib/memdebug.h [deleted file]
lib/mime.c
lib/mprintf.c
lib/mqtt.c
lib/multi.c
lib/multi_ev.c
lib/multi_ntfy.c
lib/netrc.c
lib/openldap.c
lib/pingpong.c
lib/pop3.c
lib/psl.c
lib/rand.c
lib/rename.c
lib/request.c
lib/rtsp.c
lib/select.c
lib/sendf.c
lib/setopt.c
lib/sha256.c
lib/slist.c
lib/smb.c
lib/smtp.c
lib/socketpair.c
lib/socks.c
lib/socks_gssapi.c
lib/socks_sspi.c
lib/strdup.c
lib/strerror.c
lib/system_win32.c
lib/telnet.c
lib/tftp.c
lib/transfer.c
lib/uint-bset.c
lib/uint-hash.c
lib/uint-spbset.c
lib/uint-table.c
lib/url.c
lib/urlapi.c
lib/vauth/cleartext.c
lib/vauth/cram.c
lib/vauth/digest.c
lib/vauth/digest_sspi.c
lib/vauth/gsasl.c
lib/vauth/krb5_gssapi.c
lib/vauth/krb5_sspi.c
lib/vauth/ntlm.c
lib/vauth/ntlm_sspi.c
lib/vauth/oauth2.c
lib/vauth/spnego_gssapi.c
lib/vauth/spnego_sspi.c
lib/vauth/vauth.c
lib/vquic/curl_ngtcp2.c
lib/vquic/curl_osslq.c
lib/vquic/curl_quiche.c
lib/vquic/vquic-tls.c
lib/vquic/vquic.c
lib/vssh/libssh.c
lib/vssh/libssh2.c
lib/vssh/vssh.c
lib/vtls/apple.c
lib/vtls/gtls.c
lib/vtls/hostcheck.c
lib/vtls/keylog.c
lib/vtls/mbedtls.c
lib/vtls/mbedtls_threadlock.c
lib/vtls/openssl.c
lib/vtls/rustls.c
lib/vtls/schannel.c
lib/vtls/schannel_verify.c
lib/vtls/vtls.c
lib/vtls/vtls_scache.c
lib/vtls/vtls_spack.c
lib/vtls/wolfssl.c
lib/vtls/x509asn1.c
lib/ws.c
packages/Makefile.am
packages/OS400/.checksrc [new file with mode: 0644]
scripts/checksrc.pl
src/mkhelp.pl
src/slist_wc.c
src/terminal.c
src/tool_bname.c
src/tool_cb_dbg.c
src/tool_cb_hdr.c
src/tool_cb_prg.c
src/tool_cb_rea.c
src/tool_cb_see.c
src/tool_cb_wrt.c
src/tool_cfgable.c
src/tool_cfgable.h
src/tool_dirhie.c
src/tool_doswin.c
src/tool_easysrc.c
src/tool_findfile.c
src/tool_formparse.c
src/tool_getparam.c
src/tool_getpass.c
src/tool_help.c
src/tool_helpers.c
src/tool_ipfs.c
src/tool_libinfo.c
src/tool_libinfo.h
src/tool_main.c
src/tool_msgs.c
src/tool_operate.c
src/tool_operhlp.c
src/tool_paramhlp.c
src/tool_parsecfg.c
src/tool_setopt.c
src/tool_setup.h
src/tool_ssls.c
src/tool_ssls.h
src/tool_stderr.c
src/tool_strdup.c
src/tool_strdup.h
src/tool_urlglob.c
src/tool_util.c
src/tool_vms.c
src/tool_writeout.c
src/tool_xattr.c
src/var.c
tests/Makefile.am
tests/data/Makefile.am
tests/data/test1132 [deleted file]
tests/libtest/cli_h2_pausing.c
tests/libtest/cli_h2_serverpush.c
tests/libtest/cli_h2_upgrade_extreme.c
tests/libtest/cli_hx_download.c
tests/libtest/cli_hx_upload.c
tests/libtest/cli_tls_session_reuse.c
tests/libtest/cli_upload_pausing.c
tests/libtest/cli_ws_data.c
tests/libtest/cli_ws_pingpong.c
tests/libtest/first.c
tests/libtest/lib1156.c
tests/libtest/lib1485.c
tests/libtest/lib1500.c
tests/libtest/lib1501.c
tests/libtest/lib1502.c
tests/libtest/lib1506.c
tests/libtest/lib1507.c
tests/libtest/lib1508.c
tests/libtest/lib1509.c
tests/libtest/lib1510.c
tests/libtest/lib1511.c
tests/libtest/lib1512.c
tests/libtest/lib1513.c
tests/libtest/lib1514.c
tests/libtest/lib1515.c
tests/libtest/lib1517.c
tests/libtest/lib1518.c
tests/libtest/lib1520.c
tests/libtest/lib1522.c
tests/libtest/lib1523.c
tests/libtest/lib1525.c
tests/libtest/lib1526.c
tests/libtest/lib1527.c
tests/libtest/lib1528.c
tests/libtest/lib1529.c
tests/libtest/lib1530.c
tests/libtest/lib1531.c
tests/libtest/lib1532.c
tests/libtest/lib1533.c
tests/libtest/lib1534.c
tests/libtest/lib1535.c
tests/libtest/lib1536.c
tests/libtest/lib1537.c
tests/libtest/lib1538.c
tests/libtest/lib1540.c
tests/libtest/lib1541.c
tests/libtest/lib1542.c
tests/libtest/lib1549.c
tests/libtest/lib1550.c
tests/libtest/lib1551.c
tests/libtest/lib1552.c
tests/libtest/lib1553.c
tests/libtest/lib1554.c
tests/libtest/lib1555.c
tests/libtest/lib1556.c
tests/libtest/lib1557.c
tests/libtest/lib1558.c
tests/libtest/lib1559.c
tests/libtest/lib1560.c
tests/libtest/lib1564.c
tests/libtest/lib1565.c
tests/libtest/lib1567.c
tests/libtest/lib1568.c
tests/libtest/lib1569.c
tests/libtest/lib1571.c
tests/libtest/lib1576.c
tests/libtest/lib1582.c
tests/libtest/lib1591.c
tests/libtest/lib1593.c
tests/libtest/lib1594.c
tests/libtest/lib1597.c
tests/libtest/lib1598.c
tests/libtest/lib1900.c
tests/libtest/lib1901.c
tests/libtest/lib1902.c
tests/libtest/lib1903.c
tests/libtest/lib1905.c
tests/libtest/lib1906.c
tests/libtest/lib1907.c
tests/libtest/lib1908.c
tests/libtest/lib1910.c
tests/libtest/lib1911.c
tests/libtest/lib1912.c
tests/libtest/lib1913.c
tests/libtest/lib1915.c
tests/libtest/lib1916.c
tests/libtest/lib1918.c
tests/libtest/lib1919.c
tests/libtest/lib1933.c
tests/libtest/lib1934.c
tests/libtest/lib1935.c
tests/libtest/lib1936.c
tests/libtest/lib1937.c
tests/libtest/lib1938.c
tests/libtest/lib1939.c
tests/libtest/lib1940.c
tests/libtest/lib1945.c
tests/libtest/lib1947.c
tests/libtest/lib1955.c
tests/libtest/lib1956.c
tests/libtest/lib1957.c
tests/libtest/lib1958.c
tests/libtest/lib1959.c
tests/libtest/lib1960.c
tests/libtest/lib1964.c
tests/libtest/lib1970.c
tests/libtest/lib1971.c
tests/libtest/lib1972.c
tests/libtest/lib1973.c
tests/libtest/lib1974.c
tests/libtest/lib1975.c
tests/libtest/lib1977.c
tests/libtest/lib1978.c
tests/libtest/lib2023.c
tests/libtest/lib2032.c
tests/libtest/lib2302.c
tests/libtest/lib2402.c
tests/libtest/lib2404.c
tests/libtest/lib2405.c
tests/libtest/lib2502.c
tests/libtest/lib2700.c
tests/libtest/lib3010.c
tests/libtest/lib3025.c
tests/libtest/lib3027.c
tests/libtest/lib3033.c
tests/libtest/lib3100.c
tests/libtest/lib3101.c
tests/libtest/lib3102.c
tests/libtest/lib3103.c
tests/libtest/lib3104.c
tests/libtest/lib3105.c
tests/libtest/lib3207.c
tests/libtest/lib3208.c
tests/libtest/lib500.c
tests/libtest/lib501.c
tests/libtest/lib502.c
tests/libtest/lib503.c
tests/libtest/lib504.c
tests/libtest/lib505.c
tests/libtest/lib506.c
tests/libtest/lib507.c
tests/libtest/lib508.c
tests/libtest/lib509.c
tests/libtest/lib510.c
tests/libtest/lib511.c
tests/libtest/lib512.c
tests/libtest/lib513.c
tests/libtest/lib514.c
tests/libtest/lib515.c
tests/libtest/lib516.c
tests/libtest/lib517.c
tests/libtest/lib518.c
tests/libtest/lib519.c
tests/libtest/lib520.c
tests/libtest/lib521.c
tests/libtest/lib523.c
tests/libtest/lib524.c
tests/libtest/lib525.c
tests/libtest/lib526.c
tests/libtest/lib530.c
tests/libtest/lib533.c
tests/libtest/lib536.c
tests/libtest/lib537.c
tests/libtest/lib539.c
tests/libtest/lib540.c
tests/libtest/lib541.c
tests/libtest/lib542.c
tests/libtest/lib543.c
tests/libtest/lib544.c
tests/libtest/lib547.c
tests/libtest/lib549.c
tests/libtest/lib552.c
tests/libtest/lib553.c
tests/libtest/lib554.c
tests/libtest/lib555.c
tests/libtest/lib556.c
tests/libtest/lib557.c
tests/libtest/lib558.c
tests/libtest/lib559.c
tests/libtest/lib560.c
tests/libtest/lib562.c
tests/libtest/lib564.c
tests/libtest/lib566.c
tests/libtest/lib567.c
tests/libtest/lib568.c
tests/libtest/lib569.c
tests/libtest/lib570.c
tests/libtest/lib571.c
tests/libtest/lib572.c
tests/libtest/lib573.c
tests/libtest/lib574.c
tests/libtest/lib575.c
tests/libtest/lib576.c
tests/libtest/lib578.c
tests/libtest/lib579.c
tests/libtest/lib582.c
tests/libtest/lib583.c
tests/libtest/lib586.c
tests/libtest/lib589.c
tests/libtest/lib590.c
tests/libtest/lib591.c
tests/libtest/lib597.c
tests/libtest/lib598.c
tests/libtest/lib599.c
tests/libtest/lib643.c
tests/libtest/lib650.c
tests/libtest/lib651.c
tests/libtest/lib652.c
tests/libtest/lib653.c
tests/libtest/lib654.c
tests/libtest/lib655.c
tests/libtest/lib658.c
tests/libtest/lib659.c
tests/libtest/lib661.c
tests/libtest/lib666.c
tests/libtest/lib667.c
tests/libtest/lib668.c
tests/libtest/lib670.c
tests/libtest/lib674.c
tests/libtest/lib676.c
tests/libtest/lib677.c
tests/libtest/lib678.c
tests/libtest/lib694.c
tests/libtest/lib695.c
tests/libtest/lib751.c
tests/libtest/lib753.c
tests/libtest/lib757.c
tests/libtest/lib758.c
tests/libtest/lib766.c
tests/libtest/memptr.c
tests/libtest/mk-lib1521.pl
tests/libtest/testtrace.c
tests/libtest/testutil.c
tests/server/.checksrc
tests/test1132.pl [deleted file]
tests/tunit/tool1394.c
tests/tunit/tool1604.c
tests/tunit/tool1621.c
tests/unit/unit1302.c
tests/unit/unit1303.c
tests/unit/unit1304.c
tests/unit/unit1305.c
tests/unit/unit1330.c
tests/unit/unit1395.c
tests/unit/unit1602.c
tests/unit/unit1603.c
tests/unit/unit1607.c
tests/unit/unit1609.c
tests/unit/unit1616.c
tests/unit/unit1620.c
tests/unit/unit1653.c
tests/unit/unit1661.c
tests/unit/unit1663.c
tests/unit/unit1664.c
tests/unit/unit2600.c
tests/unit/unit2604.c
tests/unit/unit2605.c
tests/unit/unit3200.c