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
This commit is contained in:
Neil Johari 2025-01-16 17:14:49 -08:00 committed by Daniel Stenberg
parent 5fd7bd4379
commit c80715169c
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -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;
}