Skip to contentSkip to conversation

http: use xmalloc with cURL

PATCH Superseded Carlo Marcelo Arenas Belón 2 participants 6 messages Aug 15, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 http: use xmalloc with cURL

f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds, 2009-05-31) never told cURL about it.

Correct that by using the cURL initializer available since version 7.12 to point to xmalloc and friends for consistency which then will pass the allocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most likely in Windows)

---
This doesn't conflict with anything and was originally based on maint (so it applies cleanly also to master and next), but is now rebased on top of jk/drop-release-pack-memory so the final product wouldn't have any chance to introduce problems (thanks Peff)

it has been built and tested in Windows through Azure Pipelines (thanks Dscho) and shouldn't introduce any build problems even with ancient versions or cURL (thanks Daniel) and while not strictly needed is a nice thing to have for consistency (thanks Junio)

 http.h | 6 ++++++
 1 file changed, 6 insertions(+)
http.h +6 -0
index b429f1cf04..e5f075dcbf 100644
@@ -22,9 +22,15 @@
 #define DEFAULT_MAX_REQUESTS 5
 #endif
 
+#if LIBCURL_VERSION_NUM >= 0x070c00
+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \
+						xrealloc, xstrdup, xcalloc)
+#endif
+
 #if LIBCURL_VERSION_NUM < 0x070704
 #define curl_global_cleanup() do { /* nothing */ } while (0)
 #endif
+
 #if LIBCURL_VERSION_NUM < 0x070800
 #define curl_global_init(a) do { /* nothing */ } while (0)
 #endif

base-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f

Signature · 1 line
2.23.0.rc2
#1 lore raw
Quoted 15 lines · Carlo Marcelo Arenas Belón

f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds, 2009-05-31) never told cURL about it.

Correct that by using the cURL initializer available since version 7.12 to point to xmalloc and friends for consistency which then will pass the allocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most likely in Windows)

---
This doesn't conflict with anything and was originally based on maint (so it applies cleanly also to master and next), but is now rebased on top of jk/drop-release-pack-memory so the final product wouldn't have any chance to introduce problems (thanks Peff)

Quoted 4 lines

it has been built and tested in Windows through Azure Pipelines (thanks Dscho) and shouldn't introduce any build problems even with ancient versions or cURL (thanks Daniel) and while not strictly needed is a nice thing to have for consistency (thanks Junio)

Thanks, all. I do not think I did anything that deserves a "thanks", but anyway.

Quoted 13 lines
 http.h | 6 ++++++
 1 file changed, 6 insertions(+)
http.h +2 -0
index b429f1cf04..e5f075dcbf 100644
@@ -22,9 +22,15 @@
 #define DEFAULT_MAX_REQUESTS 5
 #endif
 
+#if LIBCURL_VERSION_NUM >= 0x070c00
+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \

http.h line 36

Quoted 10 lines
http.h +4 -0
+						xrealloc, xstrdup, xcalloc)
+#endif
+
 #if LIBCURL_VERSION_NUM < 0x070704
 #define curl_global_cleanup() do { /* nothing */ } while (0)
 #endif
+
 #if LIBCURL_VERSION_NUM < 0x070800
 #define curl_global_init(a) do { /* nothing */ } while (0)
 #endif

The earlier version had definitions pertaining to curl_global_init() at a single place, but the above version allows arbitrary amount of unrelated stuff to be placed in between two definitions in future updates. Is that a good idea? I sort of expected "we always call global_init(), but if curl is old enough to lack it, define it as empty, and if curl is new enough to have curl_global_init_mem(), then call it instead" #if/#else/#if/#endif/#endif cascade.

Quoted 2 lines

base-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f

#2 lore raw

PATCH v2 1/1 http: use xmalloc with cURL

In reply to Carlo Marcelo Arenas Belón

f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds, 2009-05-31) never told cURL about it.

Correct that by using the cURL initializer available since version 7.12 to point to xmalloc and friends for consistency which then will pass the allocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most likely in Windows)

---

Notes:
v2: keep all global_init ifdefs together (as suggested by Junio)

 http.h | 4 ++++
 1 file changed, 4 insertions(+)
http.h +4 -0
index b429f1cf04..20a2030c94 100644
@@ -25,8 +25,12 @@
 #if LIBCURL_VERSION_NUM < 0x070704
 #define curl_global_cleanup() do { /* nothing */ } while (0)
 #endif
+
 #if LIBCURL_VERSION_NUM < 0x070800
 #define curl_global_init(a) do { /* nothing */ } while (0)
+#elseif LIBCURL_VERSION_NUM >= 0x070c00
+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \
+						xrealloc, xstrdup, xcalloc)
 #endif
 
 #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)

base-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f

Signature · 1 line
2.23.0.rc2
#3 lore raw
Quoted 1 line · Carlo Marcelo Arenas Belón

+#elseif LIBCURL_VERSION_NUM >= 0x070c00

#elif

Quoted 7 lines
http.h +2 -0
+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \
+						xrealloc, xstrdup, xcalloc)
 #endif
 
 #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)

base-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f

#4 lore raw

PATCH v3 1/1 http: use xmalloc with cURL

f0ed8226c9 (Add custom memory allocator to MinGW and MacOS builds, 2009-05-31) never told cURL about it.

Correct that by using the cURL initializer available since version 7.12 to point to xmalloc and friends for consistency which then will pass the allocation requests along when USE_NED_ALLOCATOR=YesPlease is used (most likely in Windows)

---
v3: proper use of #elif (Thanks Junio)
v2: keep all curl_global_init ifdefs together (as suggested by Junio)

 http.h | 4 ++++
 1 file changed, 4 insertions(+)
http.h +4 -0
index b429f1cf04..20a2030c94 100644
@@ -25,8 +25,12 @@
 #if LIBCURL_VERSION_NUM < 0x070704
 #define curl_global_cleanup() do { /* nothing */ } while (0)
 #endif
+
 #if LIBCURL_VERSION_NUM < 0x070800
 #define curl_global_init(a) do { /* nothing */ } while (0)
+#elif LIBCURL_VERSION_NUM >= 0x070c00
+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \
+						xrealloc, xstrdup, xcalloc)
 #endif
 
 #if (LIBCURL_VERSION_NUM < 0x070c04) || (LIBCURL_VERSION_NUM == 0x071000)

base-commit: 9827d4c185e4da728f51cd77c54a38c9de62495f

Signature · 1 line
2.23.0.rc2
#5 lore raw

http.h line 34

Quoted 6 lines · Carlo Marcelo Arenas Belón

#if LIBCURL_VERSION_NUM < 0x070800
#define curl_global_init(a) do { /* nothing */ } while (0)

http.h +3 -0
+#elif LIBCURL_VERSION_NUM >= 0x070c00
+#define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \
+						xrealloc, xstrdup, xcalloc)
 #endif

Yup. That looks better.

If your curl version is recent enough (which presumably is true for most people these days), the entire #if/#endif block is skipped while scanning for #else or #elif and #elseif willq be silently ignored; it is unfortunate that #elseif won't be flagged by CPP as a potential error X-<.