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

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

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

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

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

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

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

Closes #19626
2025-11-28 10:44:26 +01:00
..
.checksrc checksrc: disallow atoi and atol globally 2025-11-13 14:28:25 +01:00
.gitignore rtmp: remove no longer used proto member 2025-05-08 10:24:19 +02:00
CMakeLists.txt cmake: honor CURL_DISABLE_INSTALL and CURL_ENABLE_EXPORT_TARGET in lib and src 2025-11-20 00:23:08 +01:00
config2setopts.c tool_operate: fix a case of ignoring return code in operate() 2025-11-22 22:22:41 +01:00
config2setopts.h curl: remove the global argument from many functions 2025-07-10 23:28:31 +02:00
curl.rc windows: drop code and curl manifest targeting W2K and older 2025-02-24 21:00:31 +01:00
curlinfo.c curlinfo: add "ssl-sessions" as a feature to show 2025-11-19 12:58:24 +01:00
Makefile.am clang-tidy: disable clang-analyzer-security.ArrayBound 2025-08-29 03:07:42 +02:00
Makefile.inc curlx: replace sprintf with snprintf 2025-11-25 11:11:06 +01:00
mk-file-embed.pl scripts: enable strict warnings in Perl where missing, fix fallouts 2025-07-27 22:35:18 +02:00
mkhelp.pl build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
slist_wc.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
slist_wc.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
terminal.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
terminal.h curl: make warnings and other messages aware of terminal width 2024-05-28 23:12:32 +02:00
tool_bname.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_bname.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_dbg.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_cb_dbg.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_hdr.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_cb_hdr.h tool_cb_hrd: remove global pointer from 'struct HdrCbData' 2025-08-05 15:47:56 +02:00
tool_cb_prg.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_cb_prg.h curltime: use libcurl time functions in src and tests/server 2025-03-12 11:33:26 +01:00
tool_cb_rea.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_cb_rea.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_see.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_cb_see.h tool: move tool_ftruncate64 to tool_util.c 2024-04-25 09:20:38 +02:00
tool_cb_soc.c build: avoid overriding system symbols for socket functions 2025-09-20 13:44:59 +02:00
tool_cb_soc.h curl: (on linux) add MPTCP support 2024-06-07 10:54:19 +02:00
tool_cb_wrt.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_cb_wrt.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cfgable.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_cfgable.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_dirhie.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_dirhie.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_doswin.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_doswin.h build: drop Windows CE / CeGCC support 2025-11-15 15:35:23 +01:00
tool_easysrc.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_easysrc.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_filetime.c tool_filetime: cap crazy filetimes instead of erroring 2025-10-20 00:00:12 +02:00
tool_filetime.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_findfile.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_findfile.h windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
tool_formparse.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_formparse.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_getparam.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_getparam.h tool_getparam: verify that a file exists for some options 2025-11-18 11:37:08 +01:00
tool_getpass.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_getpass.h code: language cleanup in comments 2024-07-01 22:58:55 +02:00
tool_help.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_help.h curl: fix memory leak when -h is used in config file 2025-05-10 11:16:07 +02:00
tool_helpers.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_helpers.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_hugehelp.h build: drop tool_hugehelp.c.cvs, tidy up macros, drop buildconf.bat 2025-01-26 14:22:49 +01:00
tool_ipfs.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_ipfs.h ipfs: add options to disable 2024-09-21 12:08:32 +02:00
tool_libinfo.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_libinfo.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_listhelp.c tftp: check for trailing ";mode=" in URL without strstr 2025-10-15 09:59:57 +02:00
tool_main.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_main.h curl: add --parallel-max-host to limit concurrent connections per host 2025-07-31 23:30:40 +02:00
tool_msgs.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_msgs.h curl: remove first argument from helpf() 2025-08-07 16:55:39 +02:00
tool_operate.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_operate.h tool: move the error buffer to the per transfer struct 2025-09-01 08:52:57 +02:00
tool_operhlp.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_operhlp.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_paramhlp.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_paramhlp.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_parsecfg.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_parsecfg.h tool: log when loading .curlrc in verbose mode 2025-11-25 16:06:27 +01:00
tool_progress.c lib: rename curlx_timediff to curlx_timeleft_ms 2025-11-13 13:12:58 +01:00
tool_progress.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_sdecls.h curl: make the URL indexes 64 bit 2025-07-30 23:13:45 +02:00
tool_setopt.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_setopt.h tool: consider (some) curl_easy_setopt errors fatal 2025-11-07 11:12:34 +01:00
tool_setup.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_ssls.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_ssls.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_stderr.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_stderr.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_strdup.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_strdup.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_urlglob.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_urlglob.h tool_urlglob: clean up used memory on errors better 2025-11-20 22:34:34 +01:00
tool_util.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_util.h build: drop Windows CE / CeGCC support 2025-11-15 15:35:23 +01:00
tool_version.h config: rename the OS define to CURL_OS to reduce collision risk 2024-10-30 14:59:54 +01:00
tool_vms.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_vms.h tidy-up: more whitespace/indent, comments 2025-07-25 11:47:51 +02:00
tool_writeout.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_writeout.h badwords: fix two exceptions and drop them 2025-11-14 17:32:04 +01:00
tool_writeout_json.c src: stop overriding system printf symbols 2025-10-06 09:46:29 +02:00
tool_writeout_json.h curlx: move into to curlx/ 2025-05-07 11:01:15 +02:00
tool_xattr.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_xattr.h tests: always make bundles, adapt build and tests 2025-06-14 21:08:23 +02:00
var.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
var.h curl: make global truly global 2025-08-07 10:43:06 +02:00