Skip to content

Commit

Permalink
content_encoding: support use of custom libzstd memory functions
Browse files Browse the repository at this point in the history
If ZSTD_STATIC_LINKING_ONLY is defined.

This functionality was introduced in zstd v0.8.1 in 2016 here:
facebook/zstd@be6180c

Closes curl#16028
  • Loading branch information
neiljohari authored and bagder committed Jan 21, 2025
1 parent 5fd7bd4 commit c807151
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/content_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,37 @@ 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)
{
struct zstd_writer *zp = (struct zstd_writer *) writer;

(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;
}
Expand Down

0 comments on commit c807151

Please sign in to comment.