mirror of
https://github.com/facebook/zstd.git
synced 2025-12-05 00:03:19 -05:00
Merge pull request #4025 from alexlnkp/dev
Fixed all memory leaks and almost all undefined behaviour
This commit is contained in:
commit
eb541403c4
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user