Merge pull request #1494 from lzutao/fix-leak
Fix potential leak of 'outBuff' (reported by scan-build)
This commit is contained in:
commit
c5be47c8c1
@ -74,6 +74,7 @@ static int testSimpleAPI(void)
|
|||||||
|
|
||||||
static int testStreamingAPI(void)
|
static int testStreamingAPI(void)
|
||||||
{
|
{
|
||||||
|
int error_code = 0;
|
||||||
size_t const outBuffSize = ZSTD_DStreamOutSize();
|
size_t const outBuffSize = ZSTD_DStreamOutSize();
|
||||||
char* const outBuff = malloc(outBuffSize);
|
char* const outBuff = malloc(outBuffSize);
|
||||||
ZSTD_DStream* const stream = ZSTD_createDStream();
|
ZSTD_DStream* const stream = ZSTD_createDStream();
|
||||||
@ -87,6 +88,7 @@ static int testStreamingAPI(void)
|
|||||||
}
|
}
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
DISPLAY("ERROR: Could not create dstream\n");
|
DISPLAY("ERROR: Could not create dstream\n");
|
||||||
|
free(outBuff);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,13 +98,15 @@ static int testStreamingAPI(void)
|
|||||||
size_t const ret = ZSTD_initDStream(stream);
|
size_t const ret = ZSTD_initDStream(stream);
|
||||||
if (ZSTD_isError(ret)) {
|
if (ZSTD_isError(ret)) {
|
||||||
DISPLAY("ERROR: ZSTD_initDStream: %s\n", ZSTD_getErrorName(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);
|
{ size_t const ret = ZSTD_decompressStream(stream, &output, &input);
|
||||||
if (ZSTD_isError(ret)) {
|
if (ZSTD_isError(ret)) {
|
||||||
DISPLAY("ERROR: ZSTD_decompressStream: %s\n", ZSTD_getErrorName(ret));
|
DISPLAY("ERROR: ZSTD_decompressStream: %s\n", ZSTD_getErrorName(ret));
|
||||||
return 1;
|
error_code = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
@ -111,7 +115,8 @@ static int testStreamingAPI(void)
|
|||||||
|
|
||||||
if (memcmp(outBuff, EXPECTED + outputPos, output.pos) != 0) {
|
if (memcmp(outBuff, EXPECTED + outputPos, output.pos) != 0) {
|
||||||
DISPLAY("ERROR: Wrong decoded output produced\n");
|
DISPLAY("ERROR: Wrong decoded output produced\n");
|
||||||
return 1;
|
error_code = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
outputPos += output.pos;
|
outputPos += output.pos;
|
||||||
if (input.pos == input.size && output.pos < output.size) {
|
if (input.pos == input.size && output.pos < output.size) {
|
||||||
@ -121,8 +126,8 @@ static int testStreamingAPI(void)
|
|||||||
|
|
||||||
free(outBuff);
|
free(outBuff);
|
||||||
ZSTD_freeDStream(stream);
|
ZSTD_freeDStream(stream);
|
||||||
DISPLAY("Streaming API OK\n");
|
if (error_code == 0) DISPLAY("Streaming API OK\n");
|
||||||
return 0;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user