From: modbw Date: Tue, 28 Aug 2018 05:25:05 +0000 (+0200) Subject: Fixed memory leak detected by cppcheck X-Git-Tag: v0.0.29~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1299%2Fhead;p=thirdparty%2Fzstd.git Fixed memory leak detected by cppcheck cppcheck (which is run regularly in our CI environment) detected a possible memory leak. --- diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 9acceb40b..eb1a5b669 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -987,8 +987,10 @@ size_t ZDICT_trainFromBuffer_unsafe_legacy( U32 const pos = dictList[u].pos; U32 const length = dictList[u].length; U32 const printedLength = MIN(40, length); - if ((pos > samplesBuffSize) || ((pos + length) > samplesBuffSize)) + if ((pos > samplesBuffSize) || ((pos + length) > samplesBuffSize)) { + free(dictList); return ERROR(GENERIC); /* should never happen */ + } DISPLAYLEVEL(3, "%3u:%3u bytes at pos %8u, savings %7u bytes |", u, length, pos, dictList[u].savings); ZDICT_printHex((const char*)samplesBuffer+pos, printedLength);