fixed memory leaks and almost all undefined behaviour
This commit is contained in:
+8
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user