From d14edf259f912718e61e724bf8dbde4fba1db407 Mon Sep 17 00:00:00 2001 From: modbw Date: Tue, 28 Aug 2018 07:25:05 +0200 Subject: [PATCH] Fixed memory leak detected by cppcheck cppcheck (which is run regularly in our CI environment) detected a possible memory leak. --- lib/dictBuilder/zdict.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); -- 2.47.2