-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fixed all memory leaks and almost all undefined behaviour #4025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1d5e970
4f41631
01cea2e
75d0f66
b4ecf72
0b24fc0
849b2ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
ret = 10; | ||
goto _cleanUp; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ local int gz_init(gz_statep state) { | |
strm->next_out = state.state->out; | ||
state.state->x.next = strm->next_out; | ||
} | ||
|
||
free(state.state); | ||
|
||
return 0; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is incorrect :
the whole point of this function is to return a populated buffer, passed as a member of the
buffer_s
structure, effectively transferring ownership to the caller of the function (which will have to free it later, using the providedfreeBuffer()
function).Maybe this could be documented if it's not clear enough...