fixed leak

This commit is contained in:
Yann Collet 2015-11-26 12:43:28 +01:00
parent 6bcdeac954
commit 26415d3ff2
4 changed files with 51 additions and 20 deletions

View File

@ -345,6 +345,8 @@ size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbc)
{ {
if (zbc==NULL) return 0; /* support free on null */ if (zbc==NULL) return 0; /* support free on null */
ZSTD_freeDCtx(zbc->zc); ZSTD_freeDCtx(zbc->zc);
free(zbc->inBuff);
free(zbc->outBuff);
free(zbc); free(zbc);
return 0; return 0;
} }

View File

@ -186,19 +186,6 @@ static size_t ZSTD_decodeFrameHeader_Part1(ZSTD_DCtx* zc, const void* src, size_
return zc->headerSize; return zc->headerSize;
} }
/** ZSTD_decodeFrameHeader_Part2
* decode the full Frame Header
* srcSize must be the size provided by ZSTD_decodeFrameHeader_Part1
* @return : 0, or an error code, which can be tested using ZSTD_isError() */
static size_t ZSTD_decodeFrameHeader_Part2(ZSTD_DCtx* zc, const void* src, size_t srcSize)
{
const BYTE* ip = (const BYTE*)src;
if (srcSize != zc->headerSize) return ERROR(srcSize_wrong);
memset(&(zc->params), 0, sizeof(zc->params));
zc->params.windowLog = ip[4] + ZSTD_WINDOWLOG_ABSOLUTEMIN;
return 0;
}
size_t ZSTD_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcSize) size_t ZSTD_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcSize)
{ {
@ -207,10 +194,20 @@ size_t ZSTD_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcS
magicNumber = MEM_readLE32(src); magicNumber = MEM_readLE32(src);
if (magicNumber != ZSTD_MAGICNUMBER) return ERROR(prefix_unknown); if (magicNumber != ZSTD_MAGICNUMBER) return ERROR(prefix_unknown);
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
params->windowLog = ((const BYTE*)src)[4] + ZSTD_WINDOWLOG_ABSOLUTEMIN; params->windowLog = (((const BYTE*)src)[4] & 15) + ZSTD_WINDOWLOG_ABSOLUTEMIN;
return 0; return 0;
} }
/** ZSTD_decodeFrameHeader_Part2
* decode the full Frame Header
* srcSize must be the size provided by ZSTD_decodeFrameHeader_Part1
* @return : 0, or an error code, which can be tested using ZSTD_isError() */
static size_t ZSTD_decodeFrameHeader_Part2(ZSTD_DCtx* zc, const void* src, size_t srcSize)
{
if (srcSize != zc->headerSize) return ERROR(srcSize_wrong);
return ZSTD_getFrameParams(&(zc->params), src, srcSize);
}
size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
{ {

View File

@ -247,17 +247,19 @@ test-zbuff: zbufftest
test-zbuff32: zbufftest32 test-zbuff32: zbufftest32
./zbufftest32 $(ZBUFFTEST) ./zbufftest32 $(ZBUFFTEST)
valgrindTest: zstd datagen fuzzer fullbench valgrindTest: zstd datagen fuzzer fullbench zbufftest
@echo "\n ---- valgrind tests : memory analyzer ----" @echo "\n ---- valgrind tests : memory analyzer ----"
valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID) valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID)
./datagen -g16KB > tmp ./datagen -g16KB > tmp
valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID) valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
./datagen -g2930KB > tmp ./datagen -g2930KB > tmp
valgrind --leak-check=yes --error-exitcode=1 ./zstd -5 -vf tmp $(VOID) valgrind --leak-check=yes --error-exitcode=1 ./zstd -5 -vf tmp tmp2
valgrind --leak-check=yes --error-exitcode=1 ./zstd -vdf tmp2 $(VOID)
./datagen -g64MB > tmp ./datagen -g64MB > tmp
valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID) valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
@rm tmp @rm tmp
valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -i1000 -t1 valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -i1000 -t1
valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1 valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1
valgrind --leak-check=yes --error-exitcode=1 ./zbufftest -T1mn
endif endif

View File

@ -289,7 +289,8 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
U64 crcOrig, crcDest; U64 crcOrig, crcDest;
/* init */ /* init */
DISPLAYUPDATE(2, "\r%6u/%6u ", testNb, nbTests); DISPLAYUPDATE(2, "\r%6u", testNb);
if (nbTests >= testNb) DISPLAYUPDATE(2, "/%6u ", nbTests);
FUZ_rand(&coreSeed); FUZ_rand(&coreSeed);
lseed = coreSeed ^ prime1; lseed = coreSeed ^ prime1;
buffNb = FUZ_rand(&lseed) & 127; buffNb = FUZ_rand(&lseed) & 127;
@ -313,8 +314,8 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
/* Multi - segments compression test */ /* Multi - segments compression test */
XXH64_reset(&crc64, 0); XXH64_reset(&crc64, 0);
nbChunks = (FUZ_rand(&lseed) & 127) + 2; nbChunks = (FUZ_rand(&lseed) & 127) + 2;
maxTestSize = FUZ_rand(&lseed) % maxSrcLog; sampleSizeLog = FUZ_rand(&lseed) % maxSrcLog;
maxTestSize = (size_t)1 << maxTestSize; maxTestSize = (size_t)1 << sampleSizeLog;
maxTestSize += FUZ_rand(&lseed) & (maxTestSize-1); maxTestSize += FUZ_rand(&lseed) & (maxTestSize-1);
ZBUFF_compressInit(zc, (FUZ_rand(&lseed) % (20 - (sampleSizeLog/3))) + 1); ZBUFF_compressInit(zc, (FUZ_rand(&lseed) % (20 - (sampleSizeLog/3))) + 1);
totalTestSize = 0; totalTestSize = 0;
@ -379,7 +380,36 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
CHECK (crcDest!=crcOrig, "decompressed data corrupted"); CHECK (crcDest!=crcOrig, "decompressed data corrupted");
/* noisy/erroneous src decompression test */ /* noisy/erroneous src decompression test */
/* TBD later */ /* add some noise */
nbChunks = (FUZ_rand(&lseed) & 7) + 2;
for (n=0; n<nbChunks; n++)
{
size_t cStart;
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
sampleSize = (size_t)1 << sampleSizeLog;
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
if (sampleSize > cSize/3) sampleSize = cSize/3;
sampleStart = FUZ_rand(&lseed) % (srcBufferSize - sampleSize);
cStart = FUZ_rand(&lseed) % (cSize - sampleSize);
memcpy(cBuffer+cStart, srcBuffer+sampleStart, sampleSize);
}
/* try decompression on noisy data */
ZBUFF_decompressInit(zd);
totalCSize = 0;
totalGenSize = 0;
while (totalCSize < cSize)
{
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
sampleSize = (size_t)1 << sampleSizeLog;
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
readSize = sampleSize;
genSize = dstBufferSize - totalGenSize;
errorCode = ZBUFF_decompressContinue(zd, dstBuffer+totalGenSize, &genSize, cBuffer+totalCSize, &readSize);
if (ZBUFF_isError(errorCode)) break; /* error correctly detected */
}
} }
DISPLAY("\r%u fuzzer tests completed \n", testNb); DISPLAY("\r%u fuzzer tests completed \n", testNb);