From: Yann Collet Date: Wed, 20 Jun 2018 03:14:03 +0000 (-0700) Subject: fixed wrong size in pthread struct transfer X-Git-Tag: v1.3.5~3^2~8^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62469c9f41747ba78a8c616d84d7b36ffc2b7b41;p=thirdparty%2Fzstd.git fixed wrong size in pthread struct transfer --- diff --git a/lib/common/pool.c b/lib/common/pool.c index a0e2bedf0..7f9219e36 100644 --- a/lib/common/pool.c +++ b/lib/common/pool.c @@ -196,19 +196,18 @@ static POOL_ctx* POOL_resize_internal(POOL_ctx* ctx, size_t numThreads) { ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem); if (!threadPool) return NULL; /* replace existing thread pool */ - memcpy(threadPool, ctx->threads, ctx->threadCapacity); + memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(ctx->threads[0])); ZSTD_free(ctx->threads, ctx->customMem); ctx->threads = threadPool; /* Initialize additional threads */ { size_t threadId; for (threadId = ctx->threadCapacity; threadId < numThreads; ++threadId) { if (ZSTD_pthread_create(&threadPool[threadId], NULL, &POOL_thread, ctx)) { - break; + ctx->threadCapacity = threadId; + ctx->threadLimit = threadId; + return NULL; /* will release the pool */ } } - if (threadId != numThreads) { /* not all threads successfully init */ - ctx->threadCapacity = threadId; - return NULL; /* will release the pool */ - } } } + } } /* successfully expanded */ ctx->threadCapacity = numThreads; ctx->threadLimit = numThreads; diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index 425fbab39..fba99aa34 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -1643,13 +1643,13 @@ static int fuzzerTests_newAPI(U32 seed, U32 nbTests, unsigned startTest, double DISPLAYLEVEL(5, "Creating new context \n"); ZSTD_freeCCtx(zc); zc = ZSTD_createCCtx(); - CHECK(zc==NULL, "ZSTD_createCCtx allocation error"); - resetAllowed=0; + CHECK(zc == NULL, "ZSTD_createCCtx allocation error"); + resetAllowed = 0; } if ((FUZ_rand(&lseed) & 0xFF) == 132) { ZSTD_freeDStream(zd); zd = ZSTD_createDStream(); - CHECK(zd==NULL, "ZSTD_createDStream allocation error"); + CHECK(zd == NULL, "ZSTD_createDStream allocation error"); ZSTD_initDStream_usingDict(zd, NULL, 0); /* ensure at least one init */ }