aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2024-04-21 10:14:33 -0700
committerGitHub <noreply@github.com>2024-04-21 10:14:33 -0700
commiteb541403c4cdf7d5ac3325adf5cd63bdbbef8c29 (patch)
treee9e8719a36245bbdc3d15ee38d490019656596b9
parent1232d4c45d18f124e44fe382b11dee095566b610 (diff)
parent849b2ad907070c6a46cc4679f4f831eaebacc715 (diff)
downloadzstd-eb541403c4cdf7d5ac3325adf5cd63bdbbef8c29.tar.gz
Merge pull request #4025 from alexlnkp/dev
Fixed all memory leaks and almost all undefined behaviour
-rw-r--r--tests/bigdict.c11
-rw-r--r--tests/paramgrill.c1
-rw-r--r--tests/regression/result.c2
-rw-r--r--zlibWrapper/examples/minigzip.c4
-rw-r--r--zlibWrapper/gzwrite.c1
5 files changed, 13 insertions, 6 deletions
diff --git a/tests/bigdict.c b/tests/bigdict.c
index ff2bb2d7..748b60e7 100644
--- a/tests/bigdict.c
+++ b/tests/bigdict.c
@@ -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;
}
diff --git a/tests/paramgrill.c b/tests/paramgrill.c
index 8971c65d..869e966e 100644
--- a/tests/paramgrill.c
+++ b/tests/paramgrill.c
@@ -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;
}
diff --git a/tests/regression/result.c b/tests/regression/result.c
index 8ccb8751..84a8a044 100644
--- a/tests/regression/result.c
+++ b/tests/regression/result.c
@@ -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);
}
}
diff --git a/zlibWrapper/examples/minigzip.c b/zlibWrapper/examples/minigzip.c
index 1af81520..ef48d74d 100644
--- a/zlibWrapper/examples/minigzip.c
+++ b/zlibWrapper/examples/minigzip.c
@@ -234,7 +234,7 @@ int gzwrite _Z_OF((gzFile, const void *, unsigned));
int gzwrite(gzFile gz, const void *buf, unsigned len) {
z_stream *strm;
- unsigned char out[BUFLEN];
+ unsigned char out[BUFLEN] = { 0 };
if (gz == NULL || !gz->write)
return 0;
@@ -287,7 +287,7 @@ int gzclose _Z_OF((gzFile));
int gzclose(gzFile gz) {
z_stream *strm;
- unsigned char out[BUFLEN];
+ unsigned char out[BUFLEN] = { 0 };
if (gz == NULL)
return Z_STREAM_ERROR;
diff --git a/zlibWrapper/gzwrite.c b/zlibWrapper/gzwrite.c
index 67f5eda6..85b776a9 100644
--- a/zlibWrapper/gzwrite.c
+++ b/zlibWrapper/gzwrite.c
@@ -64,6 +64,7 @@ local int gz_init(gz_statep state) {
strm->next_out = state.state->out;
state.state->x.next = strm->next_out;
}
+
return 0;
}