]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
content_encoding: support use of custom libzstd memory functions
authorNeil Johari <njohari@roblox.com>
Fri, 17 Jan 2025 01:14:49 +0000 (17:14 -0800)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 21 Jan 2025 22:37:03 +0000 (23:37 +0100)
If ZSTD_STATIC_LINKING_ONLY is defined.

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

Closes #16028

lib/content_encoding.c

index 4ed47e69ef266b4d72b7018f2599398abb93d34d..e19595d5ec42bdd443245b43d8224a3d90ddd5e8 100644 (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;
 }