1
0
mirror of https://github.com/facebook/zstd.git synced 2025-08-08 17:22:10 +03:00

Merge pull request #1494 from lzutao/fix-leak

Fix potential leak of 'outBuff' (reported by scan-build)
This commit is contained in:
Yann Collet
2019-01-06 17:17:02 -08:00
committed by GitHub

View File

@@ -74,6 +74,7 @@ static int testSimpleAPI(void)
static int testStreamingAPI(void)
{
int error_code = 0;
size_t const outBuffSize = ZSTD_DStreamOutSize();
char* const outBuff = malloc(outBuffSize);
ZSTD_DStream* const stream = ZSTD_createDStream();
@@ -87,6 +88,7 @@ static int testStreamingAPI(void)
}
if (stream == NULL) {
DISPLAY("ERROR: Could not create dstream\n");
free(outBuff);
return 1;
}
@@ -96,13 +98,15 @@ static int testStreamingAPI(void)
size_t const ret = ZSTD_initDStream(stream);
if (ZSTD_isError(ret)) {
DISPLAY("ERROR: ZSTD_initDStream: %s\n", ZSTD_getErrorName(ret));
return 1;
error_code = 1;
break;
} }
{ size_t const ret = ZSTD_decompressStream(stream, &output, &input);
if (ZSTD_isError(ret)) {
DISPLAY("ERROR: ZSTD_decompressStream: %s\n", ZSTD_getErrorName(ret));
return 1;
error_code = 1;
break;
}
if (ret == 0) {
@@ -111,7 +115,8 @@ static int testStreamingAPI(void)
if (memcmp(outBuff, EXPECTED + outputPos, output.pos) != 0) {
DISPLAY("ERROR: Wrong decoded output produced\n");
return 1;
error_code = 1;
break;
}
outputPos += output.pos;
if (input.pos == input.size && output.pos < output.size) {
@@ -121,8 +126,8 @@ static int testStreamingAPI(void)
free(outBuff);
ZSTD_freeDStream(stream);
DISPLAY("Streaming API OK\n");
return 0;
if (error_code == 0) DISPLAY("Streaming API OK\n");
return error_code;
}
int main(void)