Fix several locations with potential memory leak
This commit is contained in:
@@ -316,6 +316,10 @@ int main(int argc, const char** argv)
|
|||||||
for (pos = 0; pos < inSize; pos += 2) {
|
for (pos = 0; pos < inSize; pos += 2) {
|
||||||
size_t const decStatus = ZSTD_seekable_decompress(stream, outBuffer, 1, pos);
|
size_t const decStatus = ZSTD_seekable_decompress(stream, outBuffer, 1, pos);
|
||||||
if (decStatus != 1 || outBuffer[0] != inBuffer[pos]) {
|
if (decStatus != 1 || outBuffer[0] != inBuffer[pos]) {
|
||||||
|
free(seekBuffer);
|
||||||
|
free(outBuffer);
|
||||||
|
ZSTD_seekable_freeCStream(zscs);
|
||||||
|
ZSTD_seekable_free(stream);
|
||||||
goto _test_error;
|
goto _test_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -323,6 +327,10 @@ int main(int argc, const char** argv)
|
|||||||
/* We read more than the compressed size, meaning there were some rereads.
|
/* We read more than the compressed size, meaning there were some rereads.
|
||||||
This is unneeded because we only seeked forward. */
|
This is unneeded because we only seeked forward. */
|
||||||
printf("Too much data read: %zu read, with compressed size %zu\n", buffWrapper.totalRead, seekSize);
|
printf("Too much data read: %zu read, with compressed size %zu\n", buffWrapper.totalRead, seekSize);
|
||||||
|
free(seekBuffer);
|
||||||
|
free(outBuffer);
|
||||||
|
ZSTD_seekable_freeCStream(zscs);
|
||||||
|
ZSTD_seekable_free(stream);
|
||||||
goto _test_error;
|
goto _test_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,6 +350,10 @@ int main(int argc, const char** argv)
|
|||||||
for (idx = 0; idx < sizeof(tests) / sizeof(tests[0]); idx++) {
|
for (idx = 0; idx < sizeof(tests) / sizeof(tests[0]); idx++) {
|
||||||
size_t const decStatus = ZSTD_seekable_decompress(stream, outBuffer, tests[idx].size, tests[idx].offset);
|
size_t const decStatus = ZSTD_seekable_decompress(stream, outBuffer, tests[idx].size, tests[idx].offset);
|
||||||
if (decStatus != tests[idx].size || memcmp(outBuffer, inBuffer + tests[idx].offset, tests[idx].size) != 0) {
|
if (decStatus != tests[idx].size || memcmp(outBuffer, inBuffer + tests[idx].offset, tests[idx].size) != 0) {
|
||||||
|
free(seekBuffer);
|
||||||
|
free(outBuffer);
|
||||||
|
ZSTD_seekable_freeCStream(zscs);
|
||||||
|
ZSTD_seekable_free(stream);
|
||||||
goto _test_error;
|
goto _test_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -928,6 +928,7 @@ static int UTIL_prepareFileList(const char* dirName,
|
|||||||
hFile=FindFirstFileA(path, &cFile);
|
hFile=FindFirstFileA(path, &cFile);
|
||||||
if (hFile == INVALID_HANDLE_VALUE) {
|
if (hFile == INVALID_HANDLE_VALUE) {
|
||||||
UTIL_DISPLAYLEVEL(1, "Cannot open directory '%s'\n", dirName);
|
UTIL_DISPLAYLEVEL(1, "Cannot open directory '%s'\n", dirName);
|
||||||
|
free(path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
|
|||||||
+52
-26
@@ -80,29 +80,51 @@ int main(int argc, const char** argv)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1)))
|
goto cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_overlapLog, 9)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1)))
|
goto cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, ZSTD_btopt)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_overlapLog, 9))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, 7)))
|
goto cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, 7)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, 1)))
|
goto cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 10)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, ZSTD_btopt))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, 10)))
|
goto cleanup;
|
||||||
return 1;
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, 7))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, 7))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, 1))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 10))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, 10))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (ZSTD_isError(ZSTD_DCtx_setParameter(dctx, ZSTD_d_windowLogMax, 31)))
|
if (ZSTD_isError(ZSTD_DCtx_setParameter(dctx, ZSTD_d_windowLogMax, 31))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
RDG_genBuffer(buffer, bufferSize, 1.0, 0.0, 0xbeefcafe);
|
RDG_genBuffer(buffer, bufferSize, 1.0, 0.0, 0xbeefcafe);
|
||||||
|
|
||||||
@@ -111,13 +133,17 @@ int main(int argc, const char** argv)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 10; ++i) {
|
for (i = 0; i < 10; ++i) {
|
||||||
fprintf(stderr, "Compressing 1 GB\n");
|
fprintf(stderr, "Compressing 1 GB\n");
|
||||||
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_continue))
|
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_continue)) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Compressing 1 GB\n");
|
fprintf(stderr, "Compressing 1 GB\n");
|
||||||
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_end))
|
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_end)) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Success!\n");
|
fprintf(stderr, "Success!\n");
|
||||||
|
|
||||||
|
|||||||
+57
-28
@@ -72,35 +72,59 @@ int main(int argc, const char** argv)
|
|||||||
void* roundtrip = malloc(dataSize);
|
void* roundtrip = malloc(dataSize);
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
int _exit_code = 0;
|
||||||
|
|
||||||
if (!buffer || !out || !roundtrip || !cctx || !dctx) {
|
if (!buffer || !out || !roundtrip || !cctx || !dctx) {
|
||||||
fprintf(stderr, "Allocation failure\n");
|
fprintf(stderr, "Allocation failure\n");
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1)))
|
goto _cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_overlapLog, 9)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1)))
|
goto _cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, ZSTD_btopt)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_overlapLog, 9))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, 7)))
|
goto _cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, 7)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, 1)))
|
goto _cleanup;
|
||||||
return 1;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 10)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, ZSTD_btopt))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, 10)))
|
goto _cleanup;
|
||||||
return 1;
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, 7))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, 7))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, 1))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, 10))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, 10))) {
|
||||||
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (ZSTD_isError(ZSTD_DCtx_setParameter(dctx, ZSTD_d_windowLogMax, 31)))
|
if (ZSTD_isError(ZSTD_DCtx_setParameter(dctx, ZSTD_d_windowLogMax, 31))) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
RDG_genBuffer(buffer, bufferSize, 1.0, 0.0, 0xbeefcafe);
|
RDG_genBuffer(buffer, bufferSize, 1.0, 0.0, 0xbeefcafe);
|
||||||
|
|
||||||
@@ -109,20 +133,25 @@ int main(int argc, const char** argv)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 10; ++i) {
|
for (i = 0; i < 10; ++i) {
|
||||||
fprintf(stderr, "Compressing 1 GB\n");
|
fprintf(stderr, "Compressing 1 GB\n");
|
||||||
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_continue))
|
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_continue)) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Compressing 1 GB\n");
|
fprintf(stderr, "Compressing 1 GB\n");
|
||||||
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_end))
|
if (compress(cctx, dctx, out, outSize, buffer, dataSize, roundtrip, ZSTD_e_end)) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Success!\n");
|
fprintf(stderr, "Success!\n");
|
||||||
|
|
||||||
|
_cleanup:
|
||||||
free(roundtrip);
|
free(roundtrip);
|
||||||
free(out);
|
free(out);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
ZSTD_freeDCtx(dctx);
|
ZSTD_freeDCtx(dctx);
|
||||||
ZSTD_freeCCtx(cctx);
|
ZSTD_freeCCtx(cctx);
|
||||||
return 0;
|
return _exit_code;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ static int testSimpleAPI(void)
|
|||||||
} else {
|
} else {
|
||||||
DISPLAY("ERROR: %s\n", ZSTD_getErrorName(ret));
|
DISPLAY("ERROR: %s\n", ZSTD_getErrorName(ret));
|
||||||
}
|
}
|
||||||
|
free(output);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (ret != size) {
|
if (ret != size) {
|
||||||
@@ -64,6 +65,7 @@ static int testSimpleAPI(void)
|
|||||||
}
|
}
|
||||||
if (memcmp(EXPECTED, output, size) != 0) {
|
if (memcmp(EXPECTED, output, size) != 0) {
|
||||||
DISPLAY("ERROR: Wrong decoded output produced\n");
|
DISPLAY("ERROR: Wrong decoded output produced\n");
|
||||||
|
free(output);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-17
@@ -39,24 +39,39 @@ int main(int argc, const char** argv)
|
|||||||
unsigned windowLog = 18;
|
unsigned windowLog = 18;
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
int _exit_code = 0;
|
||||||
/* Create stream */
|
/* Create stream */
|
||||||
ctx = ZSTD_createCCtx();
|
ctx = ZSTD_createCCtx();
|
||||||
if (!ctx) { return 1; }
|
if (!ctx) { return 1; }
|
||||||
/* Set parameters */
|
/* Set parameters */
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_windowLog, windowLog)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_windowLog, windowLog))) {
|
||||||
return 2;
|
_exit_code = 2;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_chainLog, 13)))
|
goto _clean_ctx;
|
||||||
return 2;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_hashLog, 14)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_chainLog, 13))) {
|
||||||
return 2;
|
_exit_code = 2;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_searchLog, 1)))
|
goto _clean_ctx;
|
||||||
return 2;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_minMatch, 7)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_hashLog, 14))) {
|
||||||
return 2;
|
_exit_code = 2;
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_targetLength, 16)))
|
goto _clean_ctx;
|
||||||
return 2;
|
}
|
||||||
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_strategy, ZSTD_fast)))
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_searchLog, 1))) {
|
||||||
return 2;
|
_exit_code = 2;
|
||||||
|
goto _clean_ctx;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_minMatch, 7))) {
|
||||||
|
_exit_code = 2;
|
||||||
|
goto _clean_ctx;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_targetLength, 16))) {
|
||||||
|
_exit_code = 2;
|
||||||
|
goto _clean_ctx;
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(ZSTD_CCtx_setParameter(ctx, ZSTD_c_strategy, ZSTD_fast))) {
|
||||||
|
_exit_code = 2;
|
||||||
|
goto _clean_ctx;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
U64 compressed = 0;
|
U64 compressed = 0;
|
||||||
const U64 toCompress = ((U64)1) << 33;
|
const U64 toCompress = ((U64)1) << 33;
|
||||||
@@ -81,22 +96,28 @@ int main(int argc, const char** argv)
|
|||||||
}
|
}
|
||||||
printf("Compressing, trying to generate a segfault \n");
|
printf("Compressing, trying to generate a segfault \n");
|
||||||
if (compress(ctx, out, srcBuffer, size)) {
|
if (compress(ctx, out, srcBuffer, size)) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto _clean_buffer;
|
||||||
}
|
}
|
||||||
compressed += size;
|
compressed += size;
|
||||||
while (compressed < toCompress) {
|
while (compressed < toCompress) {
|
||||||
const size_t block = rand() % (size - pos + 1);
|
const size_t block = rand() % (size - pos + 1);
|
||||||
if (pos == size) { pos = 0; }
|
if (pos == size) { pos = 0; }
|
||||||
if (compress(ctx, out, srcBuffer + pos, block)) {
|
if (compress(ctx, out, srcBuffer + pos, block)) {
|
||||||
return 1;
|
_exit_code = 1;
|
||||||
|
goto _clean_buffer;
|
||||||
}
|
}
|
||||||
pos += block;
|
pos += block;
|
||||||
compressed += block;
|
compressed += block;
|
||||||
}
|
}
|
||||||
printf("Compression completed successfully (no error triggered)\n");
|
printf("Compression completed successfully (no error triggered)\n");
|
||||||
|
|
||||||
|
_clean_buffer:
|
||||||
free(srcBuffer);
|
free(srcBuffer);
|
||||||
free(dstBuffer);
|
free(dstBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_clean_ctx:
|
||||||
ZSTD_freeCCtx(ctx);
|
ZSTD_freeCCtx(ctx);
|
||||||
return 0;
|
return _exit_code;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user