1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-12-26 01:59:53 +03:00

hamcorebuilder: Fix possible resource leak found by Coverity

FileClose() was not called if FileRead() failed.
This commit is contained in:
Davide Beatrici 2021-02-27 04:18:18 +01:00
parent 809f891f0c
commit 621fb087f8

View File

@ -80,15 +80,16 @@ bool BuildHamcore(const char *dst, const char *src)
}
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);
free(content);
continue;
}
FileClose(handle);
const size_t wanted_size = CompressionBufferSize(file->OriginalSize);
if (buffer_size < wanted_size)
{
@ -99,7 +100,7 @@ bool BuildHamcore(const char *dst, const char *src)
}
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);
if (ret != Z_OK)