From 377abcc02c9db9cec4f348a04a1caaa45cfa13a7 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 28 Sep 2017 02:23:44 -0700 Subject: [PATCH] zstdmt : better behavior when freeing a context right after a memory allocation error wait for all jobs to be completed, so that freeing can happen safely --- lib/compress/zstdmt_compress.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 202d61b6..5001f4a0 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -1014,8 +1014,10 @@ size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx, if (input->size > input->pos) { /* support NULL input */ if (mtctx->inBuff.buffer.start == NULL) { mtctx->inBuff.buffer = ZSTDMT_getBuffer(mtctx->bufPool); - if (mtctx->inBuff.buffer.start == NULL) + if (mtctx->inBuff.buffer.start == NULL) { + ZSTDMT_waitForAllJobsCompleted(mtctx); return ERROR(memory_allocation); + } mtctx->inBuff.filled = 0; } { size_t const toLoad = MIN(input->size - input->pos, mtctx->inBuffSize - mtctx->inBuff.filled);