]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fixed memory leak detected by cppcheck 1299/head
authormodbw <m.weisser.m@gmail.com>
Tue, 28 Aug 2018 05:25:05 +0000 (07:25 +0200)
committerGitHub <noreply@github.com>
Tue, 28 Aug 2018 05:25:05 +0000 (07:25 +0200)
cppcheck (which is run regularly in our CI environment)  detected a possible memory leak.

lib/dictBuilder/zdict.c

index 9acceb40be07673946de094f0b6631dd6caf0a72..eb1a5b66987f620b4bc383fd8aac0c3b220d9789 100644 (file)
@@ -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);