Remove excess checks before free()

References:
- https://pubs.opengroup.org/onlinepubs/009695399/functions/free.html
- https://stackoverflow.com/a/18775633
This commit is contained in:
Herman Semenov 2025-02-28 04:59:34 +03:00 committed by Nathan Moinvaziri
parent 55db144e03
commit dd91a4db20
11 changed files with 13 additions and 28 deletions

View File

@ -211,8 +211,7 @@ void mz_stream_ioapi_delete(void **stream) {
if (!stream)
return;
ioapi = (mz_stream_ioapi *)*stream;
if (ioapi)
free(ioapi);
free(ioapi);
*stream = NULL;
}

View File

@ -537,7 +537,6 @@ void mz_stream_raw_delete(void **stream) {
if (!stream)
return;
raw = (mz_stream_raw *)*stream;
if (raw)
free(raw);
free(raw);
*stream = NULL;
}

View File

@ -372,8 +372,7 @@ void mz_stream_buffered_delete(void **stream) {
if (!stream)
return;
buffered = (mz_stream_buffered *)*stream;
if (buffered)
free(buffered);
free(buffered);
*stream = NULL;
}

View File

@ -336,8 +336,7 @@ void mz_stream_bzip_delete(void **stream) {
if (!stream)
return;
bzip = (mz_stream_bzip *)*stream;
if (bzip)
free(bzip);
free(bzip);
*stream = NULL;
}

View File

@ -443,8 +443,7 @@ void mz_stream_lzma_delete(void **stream) {
if (!stream)
return;
lzma = (mz_stream_lzma *)*stream;
if (lzma)
free(lzma);
free(lzma);
*stream = NULL;
}

View File

@ -186,8 +186,7 @@ void mz_stream_os_delete(void **stream) {
if (!stream)
return;
posix = (mz_stream_posix *)*stream;
if (posix)
free(posix);
free(posix);
*stream = NULL;
}

View File

@ -315,8 +315,7 @@ void mz_stream_pkcrypt_delete(void **stream) {
if (!stream)
return;
pkcrypt = (mz_stream_pkcrypt *)*stream;
if (pkcrypt)
free(pkcrypt);
free(pkcrypt);
*stream = NULL;
}

View File

@ -404,11 +404,8 @@ void mz_stream_split_delete(void **stream) {
return;
split = (mz_stream_split *)*stream;
if (split) {
if (split->path_cd)
free(split->path_cd);
if (split->path_disk)
free(split->path_disk);
free(split->path_cd);
free(split->path_disk);
free(split);
}
*stream = NULL;

View File

@ -369,8 +369,7 @@ void mz_stream_zlib_delete(void **stream) {
if (!stream)
return;
zlib = (mz_stream_zlib *)*stream;
if (zlib)
free(zlib);
free(zlib);
*stream = NULL;
}

View File

@ -327,8 +327,7 @@ void mz_stream_zstd_delete(void **stream) {
if (!stream)
return;
zstd = (mz_stream_zstd *)*stream;
if (zstd)
free(zstd);
free(zstd);
*stream = NULL;
}

View File

@ -1416,9 +1416,7 @@ void mz_zip_delete(void **handle) {
if (!handle)
return;
zip = (mz_zip *)*handle;
if (zip) {
free(zip);
}
free(zip);
*handle = NULL;
}
@ -1560,8 +1558,7 @@ int32_t mz_zip_set_comment(void *handle, const char *comment) {
int32_t comment_size = 0;
if (!zip || !comment)
return MZ_PARAM_ERROR;
if (zip->comment)
free(zip->comment);
free(zip->comment);
comment_size = (int32_t)strlen(comment);
if (comment_size > UINT16_MAX)
return MZ_PARAM_ERROR;