Skip to content

Commit b7d55cf

Browse files
committed
fix issue #3119
fix segfault error when running zstreamtest with MALLOC_PERTURB_
1 parent 9abecfb commit b7d55cf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/common/pool.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/* ====== Dependencies ======= */
1313
#include "zstd_deps.h" /* size_t */
1414
#include "debug.h" /* assert */
15-
#include "zstd_internal.h" /* ZSTD_customMalloc, ZSTD_customFree */
15+
#include "zstd_internal.h" /* ZSTD_customCalloc, ZSTD_customFree */
1616
#include "pool.h"
1717

1818
/* ====== Compiler specifics ====== */
@@ -126,7 +126,7 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
126126
* empty and full queues.
127127
*/
128128
ctx->queueSize = queueSize + 1;
129-
ctx->queue = (POOL_job*)ZSTD_customMalloc(ctx->queueSize * sizeof(POOL_job), customMem);
129+
ctx->queue = (POOL_job*)ZSTD_customCalloc(ctx->queueSize * sizeof(POOL_job), customMem);
130130
ctx->queueHead = 0;
131131
ctx->queueTail = 0;
132132
ctx->numThreadsBusy = 0;
@@ -140,7 +140,7 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
140140
}
141141
ctx->shutdown = 0;
142142
/* Allocate space for the thread handles */
143-
ctx->threads = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
143+
ctx->threads = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
144144
ctx->threadCapacity = 0;
145145
ctx->customMem = customMem;
146146
/* Check for errors */
@@ -220,7 +220,7 @@ static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
220220
return 0;
221221
}
222222
/* numThreads > threadCapacity */
223-
{ ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
223+
{ ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
224224
if (!threadPool) return 1;
225225
/* replace existing thread pool */
226226
ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));

0 commit comments

Comments
 (0)