fixed leak
This commit is contained in:
parent
6bcdeac954
commit
26415d3ff2
@ -345,6 +345,8 @@ size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbc)
|
||||
{
|
||||
if (zbc==NULL) return 0; /* support free on null */
|
||||
ZSTD_freeDCtx(zbc->zc);
|
||||
free(zbc->inBuff);
|
||||
free(zbc->outBuff);
|
||||
free(zbc);
|
||||
return 0;
|
||||
}
|
||||
|
@ -186,19 +186,6 @@ static size_t ZSTD_decodeFrameHeader_Part1(ZSTD_DCtx* zc, const void* src, size_
|
||||
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)
|
||||
{
|
||||
@ -207,10 +194,20 @@ size_t ZSTD_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcS
|
||||
magicNumber = MEM_readLE32(src);
|
||||
if (magicNumber != ZSTD_MAGICNUMBER) return ERROR(prefix_unknown);
|
||||
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;
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
|
@ -247,17 +247,19 @@ test-zbuff: zbufftest
|
||||
test-zbuff32: zbufftest32
|
||||
./zbufftest32 $(ZBUFFTEST)
|
||||
|
||||
valgrindTest: zstd datagen fuzzer fullbench
|
||||
valgrindTest: zstd datagen fuzzer fullbench zbufftest
|
||||
@echo "\n ---- valgrind tests : memory analyzer ----"
|
||||
valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID)
|
||||
./datagen -g16KB > tmp
|
||||
valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
|
||||
./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
|
||||
valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
|
||||
@rm tmp
|
||||
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 ./zbufftest -T1mn
|
||||
|
||||
endif
|
||||
|
@ -289,7 +289,8 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
||||
U64 crcOrig, crcDest;
|
||||
|
||||
/* init */
|
||||
DISPLAYUPDATE(2, "\r%6u/%6u ", testNb, nbTests);
|
||||
DISPLAYUPDATE(2, "\r%6u", testNb);
|
||||
if (nbTests >= testNb) DISPLAYUPDATE(2, "/%6u ", nbTests);
|
||||
FUZ_rand(&coreSeed);
|
||||
lseed = coreSeed ^ prime1;
|
||||
buffNb = FUZ_rand(&lseed) & 127;
|
||||
@ -313,8 +314,8 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
||||
/* Multi - segments compression test */
|
||||
XXH64_reset(&crc64, 0);
|
||||
nbChunks = (FUZ_rand(&lseed) & 127) + 2;
|
||||
maxTestSize = FUZ_rand(&lseed) % maxSrcLog;
|
||||
maxTestSize = (size_t)1 << maxTestSize;
|
||||
sampleSizeLog = FUZ_rand(&lseed) % maxSrcLog;
|
||||
maxTestSize = (size_t)1 << sampleSizeLog;
|
||||
maxTestSize += FUZ_rand(&lseed) & (maxTestSize-1);
|
||||
ZBUFF_compressInit(zc, (FUZ_rand(&lseed) % (20 - (sampleSizeLog/3))) + 1);
|
||||
totalTestSize = 0;
|
||||
@ -379,7 +380,36 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
||||
CHECK (crcDest!=crcOrig, "decompressed data corrupted");
|
||||
|
||||
/* 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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user