From: Neil Johari Date: Fri, 17 Jan 2025 01:14:49 +0000 (-0800) Subject: content_encoding: support use of custom libzstd memory functions X-Git-Tag: curl-8_12_0~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c80715169c7be66260fc1d50e954f729bd5cb652;p=thirdparty%2Fcurl.git content_encoding: support use of custom libzstd memory functions If ZSTD_STATIC_LINKING_ONLY is defined. This functionality was introduced in zstd v0.8.1 in 2016 here: facebook/zstd@be6180c Closes #16028 --- diff --git a/lib/content_encoding.c b/lib/content_encoding.c index 4ed47e69ef..e19595d5ec 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -742,6 +742,20 @@ struct zstd_writer { void *decomp; }; +#ifdef ZSTD_STATIC_LINKING_ONLY +static void *Curl_zstd_alloc(void *opaque, size_t size) +{ + (void)opaque; + return Curl_cmalloc(size); +} + +static void Curl_zstd_free(void *opaque, void *address) +{ + (void)opaque; + Curl_cfree(address); +} +#endif + static CURLcode zstd_do_init(struct Curl_easy *data, struct Curl_cwriter *writer) { @@ -749,7 +763,16 @@ static CURLcode zstd_do_init(struct Curl_easy *data, (void)data; +#ifdef ZSTD_STATIC_LINKING_ONLY + zp->zds = ZSTD_createDStream_advanced((ZSTD_customMem) { + .customAlloc = Curl_zstd_alloc, + .customFree = Curl_zstd_free, + .opaque = NULL + }); +#else zp->zds = ZSTD_createDStream(); +#endif + zp->decomp = NULL; return zp->zds ? CURLE_OK : CURLE_OUT_OF_MEMORY; }