]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Bypass memory alignment compensation if not using custom allocator.
authorNathan Moinvaziri <nathan@nathanm.com>
Tue, 25 Jan 2022 04:58:54 +0000 (20:58 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 15 Mar 2022 17:32:15 +0000 (18:32 +0100)
zutil.c

diff --git a/zutil.c b/zutil.c
index 20f5ac120c0e9e66483b541db22e8a8340e458d5..c3ef19f5bcef7ff112b530a33d48cfc2a798cb15 100644 (file)
--- a/zutil.c
+++ b/zutil.c
@@ -117,6 +117,10 @@ void Z_INTERNAL *zng_calloc_aligned(zng_calloc_func zalloc, void *opaque, unsign
     int32_t alloc_size, align_diff;
     void *ptr;
 
+    /* If no custom calloc function used then call zlib-ng's aligned calloc */
+    if (zalloc == zng_calloc)
+        return zng_calloc(opaque, items, size);
+
     /* Allocate enough memory for proper alignment and to store the original memory pointer */
     alloc_size = sizeof(void *) + (items * size) + align;
     ptr = zalloc(opaque, 1, alloc_size);
@@ -138,6 +142,11 @@ void Z_INTERNAL *zng_calloc_aligned(zng_calloc_func zalloc, void *opaque, unsign
 }
 
 void Z_INTERNAL zng_cfree_aligned(zng_cfree_func zfree, void *opaque, void *ptr) {
+    /* If no custom cfree function used then call zlib-ng's aligned cfree */
+    if (zfree == zng_cfree) {
+        zng_cfree(opaque, ptr);
+        return;
+    }
     if (!ptr)
         return;