1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

fixed memory leaks and almost all undefined behaviour

This commit is contained in:
Alex Murkoff
2024-04-13 02:24:14 +07:00
parent 592de19843
commit 1d5e9705db
10 changed files with 19 additions and 10 deletions

View File

@ -70,12 +70,14 @@ int main(int argc, const char** argv)
char* buffer = (char*)malloc(bufferSize);
void* out = malloc(outSize);
void* roundtrip = malloc(dataSize);
int _exit_code = 0;
(void)argc;
(void)argv;
if (!buffer || !out || !roundtrip || !cctx || !dctx) {
fprintf(stderr, "Allocation failure\n");
return 1;
_exit_code = 1;
goto cleanup;
}
if (ZSTD_isError(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, 31)))
@ -119,10 +121,13 @@ int main(int argc, const char** argv)
fprintf(stderr, "Success!\n");
goto cleanup;
cleanup:
free(roundtrip);
free(out);
free(buffer);
ZSTD_freeDCtx(dctx);
ZSTD_freeCCtx(cctx);
return 0;
ZSTD_freeDCtx(dctx);
return _exit_code;
}

View File

@ -1273,7 +1273,6 @@ static int createBuffers(buffers_t* buff, const char* const * const fileNamesTab
f = fopen(fileNamesTable[n], "rb");
if (f==NULL) {
DISPLAY("impossible to open file %s\n", fileNamesTable[n]);
fclose(f);
ret = 10;
goto _cleanUp;
}

View File

@ -24,5 +24,7 @@ char const* result_get_error_string(result_t result) {
return "decompression error";
case result_error_round_trip_error:
return "round trip error";
default:
return "unknown error - " + result_get_error(result);
}
}

View File

@ -31,7 +31,7 @@ static BYTE SEQ_randByte(unsigned* src)
SEQ_stream SEQ_initStream(unsigned seed)
{
SEQ_stream stream;
SEQ_stream stream = {};
stream.state = 0;
XXH64_reset(&stream.xxh, 0);
stream.seed = seed;