1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Merge PR #1280: hamcorebuilder: Fix possible resource leak found by Coverity

This commit is contained in:
Davide Beatrici 2021-02-27 04:37:57 +01:00 committed by GitHub
commit d161b75a7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,15 +80,16 @@ bool BuildHamcore(const char *dst, const char *src)
} }
uint8_t *content = malloc(file->OriginalSize); uint8_t *content = malloc(file->OriginalSize);
if (!FileRead(handle, content, file->OriginalSize)) int ret = FileRead(handle, content, file->OriginalSize);
FileClose(handle);
if (!ret)
{ {
printf("FileRead() failed for \"%s\", skipping...\n", path); printf("FileRead() failed for \"%s\", skipping...\n", path);
free(content); free(content);
continue; continue;
} }
FileClose(handle);
const size_t wanted_size = CompressionBufferSize(file->OriginalSize); const size_t wanted_size = CompressionBufferSize(file->OriginalSize);
if (buffer_size < wanted_size) if (buffer_size < wanted_size)
{ {
@ -99,7 +100,7 @@ bool BuildHamcore(const char *dst, const char *src)
} }
file->Size = buffer_size; file->Size = buffer_size;
const int ret = compress(buffer, (uLongf *)&file->Size, content, (uLong)file->OriginalSize); ret = compress(buffer, (uLongf *)&file->Size, content, (uLong)file->OriginalSize);
free(content); free(content);
if (ret != Z_OK) if (ret != Z_OK)