From: Yann Collet Date: Wed, 11 Jan 2017 14:58:05 +0000 (+0100) Subject: fixed ZSTDMT_createCCtx() : checked inner objects are properly created X-Git-Tag: v1.1.3^2~19^2~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=085179bb78248796775193433c0596969511da55;p=thirdparty%2Fzstd.git fixed ZSTDMT_createCCtx() : checked inner objects are properly created --- diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 5c7b654ab..5fbf32b93 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -206,12 +206,16 @@ ZSTDMT_CCtx *ZSTDMT_createCCtx(unsigned nbThreads) cctx->factory = POOL_create(nbThreads, 1); cctx->buffPool = ZSTDMT_createBufferPool(nbThreads); cctx->cctxPool = ZSTDMT_createCCtxPool(nbThreads); - pthread_mutex_init(&cctx->jobCompleted_mutex, NULL); + if (!cctx->factory | !cctx->buffPool | !cctx->cctxPool) { /* one object was not created */ + ZSTDMT_freeCCtx(cctx); + return NULL; + } + pthread_mutex_init(&cctx->jobCompleted_mutex, NULL); /* Todo : check init function return */ pthread_cond_init(&cctx->jobCompleted_cond, NULL); return cctx; } -size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx) /* incompleted ! */ +size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx) { POOL_free(mtctx->factory); ZSTDMT_freeBufferPool(mtctx->buffPool);