A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and
Go to file
Viktor Szakats 3bb5e58c10
memory: make function overrides work reliably in unity builds
Fixing:
- HTTPS-RR builds with c-ares and Linux MUSL.
- curl-for-win minimal builds with Linux MUSL.

It should fix all other kinds of entaglement between curl's redefintions
of system symbols and system (or 3rd-party) headers sensitive to that.

It also syncs memory override behavior between unity & non-unity builds,
thus reducing build variations.

The idea is to define and declare everything once in `curl_setup.h`,
without overriding any system symbols with curl ones yet. Then, like
before this patch, override them, if necessary, in each source file via
`curl_memory.h` and `memdebug.h`, after including system headers.
To ensure a clean slate with no overrides at the beginning of each
source file, reset all of them unconditionally at the end of
`curl_setup.h`, by including `curl_mem_undef.h`. (This assumes
`curl_setup.h` is always included first, which is already the case
throughout the codebase.)

`curl_mem_undef.h` can also be included explicitly wherever overrides
are causing problems. E.g. in tests which use unity-style builds and
a previously included `curl_memory.h`/`memdebug.h` can be spilling into
other source files.

The simplified role of the two override headers:
- `curl_memory.h`: overrides system memory allocator functions to
  libcurl ones, when memory tracing (aka `CURLDEBUG`) is disabled.
- `memdebug.h`: overrides system memory allocator and some other
  functions to curl debug functions, when memory tracing is enabled.

Changed made in this patch, step-by-step:
- curl_memory.h: move allocator typedefs and protos to `curl_setup.h`.
- memdebug.h: move `ALLOC_*` macros to `curl_setup.h`.
- memdebug.h: move allocator protos to `curl_setup.h`.
- memdebug.h: move `Curl_safefree()` macro to `curl_setup.h`.
  (it's a regular macro, with a one-time, global, definition.)
- curl_memory.h: move system symbol undefs to a new, separate header:
  `curl_mem_undef.h`.
- curl_setup.h: include `curl_mem_undef.h` at the end, unconditionally,
  to reset system symbol macros after each inclusion.
- handle `sclose()` and `fake_sclose()` in `curl_setup.h`. They are not
  system symbols, a one-time definition does the job.

Also:
- GHA/linux: enable unity mode for the HTTP-RR c-ares MUSL job.
  Follow-up to 17ab4d62e6 #16413

That said, I'd still find it better to avoid redefining system macros.
To communicate clearly the fact that they are not the original system
calls and they do behave differently. And, it would allow dropping the
undef/redef dance in each source file, and maintaining the logic with
it. The "last #include files should be in this order" comments in each
source would also become unnecessary. Also the trick of using
`(func)` (or interim macros) to call the non-overridden function where
required. This method works for printf and most everything else already.
For `_tcsdup`, socket and fopen functions this could work without
disturbing the codebase much.

Ref: #16428 (clean reboot of)

Closes #17827
2025-07-28 17:45:04 +02:00
.circleci CI: sync curl download command-line options 2025-07-07 17:34:47 +02:00
.github memory: make function overrides work reliably in unity builds 2025-07-28 17:45:04 +02:00
CMake build: bump minimum required mingw-w64 to v3.0 (from v1.0) 2025-07-28 12:43:02 +02:00
docs curl: add long option '--out-null' 2025-07-28 14:57:38 +02:00
include CURLOPT: bump CURLHEADER_* macros to long, drop casts 2025-07-28 17:31:33 +02:00
lib memory: make function overrides work reliably in unity builds 2025-07-28 17:45:04 +02:00
LICENSES copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
m4 tidy-up: prefer ifdef/ifndef for single checks 2025-07-27 22:35:17 +02:00
packages tidy-up: more whitespace/indent, comments 2025-07-25 11:47:51 +02:00
plan9 copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
projects checksrc-all: rewrite in Perl, remove checksrc.bat 2025-07-11 12:28:46 +02:00
scripts contrithanks: fix for BSD sed tool 2025-07-28 17:29:26 +02:00
src curl: add long option '--out-null' 2025-07-28 14:57:38 +02:00
tests CURLOPT: bump CURLHEADER_* macros to long, drop casts 2025-07-28 17:31:33 +02:00
winbuild vquic: drop msh3 2025-07-27 17:57:17 +02:00
.dir-locals.el copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
.git-blame-ignore-revs copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
.gitattributes winbuild: MS-DOS batch tidy-ups 2024-07-02 19:26:15 +02:00
.gitignore tidy-up: .gitignore lines mostly 2025-01-27 20:59:46 +01:00
.mailmap ws: tests and fixes 2025-06-02 11:15:38 +02:00
acinclude.m4 build: drop HAVE_SYS_SOCKET_H and HAVE_SYS_TIME_H macros 2025-06-15 18:44:39 +02:00
appveyor.sh appveyor: drop VS2008 CI job, move OpenSSL 1.0.2 to VS2010 2025-07-01 19:47:01 +02:00
appveyor.yml windows: fix if_nametoindex() detection with autotools, improve with cmake 2025-07-21 13:30:01 +02:00
buildconf copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
CHANGES.md CHANGES: rename to CHANGES.md, no longer generated 2024-08-01 13:37:12 +02:00
CMakeLists.txt build: bump minimum required mingw-w64 to v3.0 (from v1.0) 2025-07-28 12:43:02 +02:00
configure.ac vquic: drop msh3 2025-07-27 17:57:17 +02:00
COPYING COPYING: bump copyright year range to 1996 - 2025 2025-01-01 21:12:12 +01:00
curl-config.in curl-config: fix whitespace in usage text 2025-06-27 01:03:08 +02:00
Dockerfile GHA: update debian:bookworm-slim Docker digest to 2424c18 2025-07-22 19:47:47 +02:00
GIT-INFO.md build: drop tool_hugehelp.c.cvs, tidy up macros, drop buildconf.bat 2025-01-26 14:22:49 +01:00
libcurl.pc.in configure: do not echo most inherited LDFLAGS to config files 2024-11-14 09:55:45 +01:00
Makefile.am vquic: drop msh3 2025-07-27 17:57:17 +02:00
README docs: minor grammar fixes 2022-09-29 10:44:12 +02:00
README.md spacecheck.pl: drop more exceptions 2025-05-13 16:01:07 +02:00
RELEASE-NOTES RELEASE-NOTES: synced 2025-07-28 13:04:36 +02:00
renovate.json ci: fix ldap install location and add renovate rule for openldap 2025-07-15 14:54:44 +01:00
REUSE.toml checksrc: reduce exceptions, apply again to curlx 2025-06-27 17:33:35 +02:00
SECURITY.md docs: Clarify OpenSSF Best Practices vs Scorecard 2024-08-22 11:50:20 +02:00

curl logo

curl is a command-line tool for transferring data specified with URL syntax. Learn how to use curl by reading the manpage or everything curl.

Find out how to install curl by reading the INSTALL document.

libcurl is the library curl is using to do its job. It is readily available to be used by your software. Read the libcurl manpage to learn how.

Open Source

curl is Open Source and is distributed under an MIT-like license.

Contact

Contact us on a suitable mailing list or use GitHub issues/ pull requests/ discussions.

All contributors to the project are listed in the THANKS document.

Commercial support

For commercial support, maybe private and dedicated help with your problems or applications using (lib)curl visit the support page.

Website

Visit the curl website for the latest news and downloads.

Source code

Download the latest source from the Git server:

git clone https://github.com/curl/curl.git

Security problems

Report suspected security problems via our HackerOne page and not in public.

Notice

curl contains pieces of source code that is Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan. This notice is included here to comply with the distribution terms.

Backers

Thank you to all our backers 🙏 Become a backer.

Sponsors

Support this project by becoming a sponsor.