[all] general: fix possible memory leaks with realloc usage

This commit is contained in:
Geoffrey McRae
2025-03-09 02:56:20 +11:00
parent 5382a94945
commit a421329d9a
3 changed files with 20 additions and 10 deletions

View File

@@ -626,12 +626,13 @@ static bool appendData(KVMFRUserData * dst, const void * src, const size_t size)
if (size > dst->size - dst->used)
{
size_t newSize = dst->size + max(1024, size);
dst->data = realloc(dst->data, newSize);
if (!dst->data)
void * tmp = realloc(dst->data, newSize);
if (!tmp)
{
DEBUG_ERROR("Out of memory");
return false;
}
dst->data = tmp;
memset(dst->data + dst->size, 0, newSize - dst->size);
dst->size = newSize;