]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixes suggested by @ebiggers
authorYann Collet <yann.collet.73@gmail.com>
Sun, 8 Oct 2023 06:29:42 +0000 (23:29 -0700)
committerYann Collet <yann.collet.73@gmail.com>
Sun, 8 Oct 2023 06:29:42 +0000 (23:29 -0700)
lib/compress/zstdmt_compress.c

index 236daab2627d691f6e3665da46de6231abf722de..1b47734c29d9145bbfb877c542192fe27d057a24 100644 (file)
@@ -369,18 +369,18 @@ static void ZSTDMT_freeCCtxPool(ZSTDMT_CCtxPool* pool)
 static ZSTDMT_CCtxPool* ZSTDMT_createCCtxPool(int nbWorkers,
                                               ZSTD_customMem cMem)
 {
-    ZSTDMT_CCtxPool* const cctxPool = (ZSTDMT_CCtxPool*) ZSTD_customCalloc(
-        sizeof(ZSTDMT_CCtxPool) + (nbWorkers-1)*sizeof(ZSTD_CCtx*), cMem);
+    ZSTDMT_CCtxPool* const cctxPool = 
+        (ZSTDMT_CCtxPool*) ZSTD_customCalloc(sizeof(ZSTDMT_CCtxPool), cMem);
     assert(nbWorkers > 0);
     if (!cctxPool) return NULL;
     if (ZSTD_pthread_mutex_init(&cctxPool->poolMutex, NULL)) {
-        ZSTDMT_freeCCtxPool(cctxPool);
+        ZSTD_customFree(cctxPool, cMem);
         return NULL;
     }
     cctxPool->totalCCtx = nbWorkers;
     cctxPool->cctxs = (ZSTD_CCtx**)ZSTD_customCalloc(nbWorkers * sizeof(ZSTD_CCtx*), cMem);
     if (!cctxPool->cctxs) {
-        ZSTD_customFree(cctxPool, cMem);
+        ZSTDMT_freeCCtxPool(cctxPool);
         return NULL;
     }
     cctxPool->cMem = cMem;
@@ -408,8 +408,7 @@ static size_t ZSTDMT_sizeof_CCtxPool(ZSTDMT_CCtxPool* cctxPool)
 {
     ZSTD_pthread_mutex_lock(&cctxPool->poolMutex);
     {   unsigned const nbWorkers = cctxPool->totalCCtx;
-        size_t const poolSize = sizeof(*cctxPool)
-                                + (nbWorkers-1) * sizeof(ZSTD_CCtx*);
+        size_t const poolSize = sizeof(*cctxPool);
         size_t const arraySize = cctxPool->totalCCtx * sizeof(ZSTD_CCtx*);
         size_t totalCCtxSize = 0;
         unsigned u;