From: Yann Collet Date: Sun, 8 Oct 2023 06:29:42 +0000 (-0700) Subject: fixes suggested by @ebiggers X-Git-Tag: v1.5.6^2~112^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c87ad5bdb59c95c16871ff99d83ec3b09bd742c8;p=thirdparty%2Fzstd.git fixes suggested by @ebiggers --- diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 236daab26..1b47734c2 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -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;