From 2f8088f9dfdff80cfa100f2d4d10b68227bd2414 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 1 Feb 2025 21:23:36 -0800 Subject: [PATCH] fixed one race scenario --- lib/compress/zstdmt_compress.c | 3 +-- tests/zstreamtest.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 91f158084..68f911149 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -837,6 +837,7 @@ _endJob: job->cSize += lastCBlockSize; job->consumed = job->src.size; /* when job->consumed == job->src.size , compression job is presumed completed */ if (job->flush_mutex != NULL) { + assert(job->flush_cond != NULL); ZSTD_pthread_mutex_unlock(&job->job_mutex); ZSTD_PTHREAD_MUTEX_LOCK(job->flush_mutex); ZSTD_pthread_cond_signal(job->flush_cond); /* warns some more data is ready to be flushed */ @@ -1603,8 +1604,6 @@ static size_t ZSTDMT_flushProduced(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, u DEBUGLOG(5, "dstBuffer released"); mtctx->jobs[wJobID].dstBuff = g_nullBuffer; mtctx->jobs[wJobID].cSize = 0; /* ensure this job slot is considered "not started" in future check */ - mtctx->jobs[wJobID].flush_mutex = NULL; - mtctx->jobs[wJobID].flush_cond = NULL; mtctx->consumed += srcSize; mtctx->produced += cSize; mtctx->doneJobID++; diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index b8290fefc..e87a52328 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -2900,7 +2900,7 @@ static int fuzzerTests_newAPI(U32 seed, int nbTests, int startTest, U32 lseed; int opaqueAPI; const BYTE* srcBuffer; - size_t totalTestSize, totalGenSize, cSize; + size_t totalTestSize, totalGenSize, cSize=0; XXH64_state_t xxhState; U64 crcOrig; U32 resetAllowed = 1; -- 2.47.2