From: Yann Collet Date: Thu, 6 Apr 2017 08:25:26 +0000 (-0700) Subject: ensure cctx internal buffer is correctly sized in case of memory error X-Git-Tag: v1.2.0^2~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0181fef545229e54b77e78dcf1d18078010940b3;p=thirdparty%2Fzstd.git ensure cctx internal buffer is correctly sized in case of memory error --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 6032e16bc..4ad978a4b 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -278,6 +278,7 @@ static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc, size_t const neededSpace = tableSpace + (256*sizeof(U32)) /* huffTable */ + tokenSpace + (((params.cParams.strategy == ZSTD_btopt) || (params.cParams.strategy == ZSTD_btopt2)) ? optSpace : 0); if (zc->workSpaceSize < neededSpace) { + zc->workSpaceSize = 0; ZSTD_free(zc->workSpace, zc->customMem); zc->workSpace = ZSTD_malloc(neededSpace, zc->customMem); if (zc->workSpace == NULL) return ERROR(memory_allocation);