1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-28 00:15:06 +00:00

Don't assume realloc always succeeds

This commit is contained in:
Evil Eye 2024-08-20 19:49:13 +02:00
parent 527fa053c5
commit 4652151630

View File

@ -101,14 +101,22 @@ namespace LuaUtil
<< " is blocked because Lua memory limit (configurable in settings.cfg) is exceeded";
return nullptr;
}
self->mTotalMemoryUsage += smallAllocDelta + bigAllocDelta;
self->mSmallAllocMemoryUsage += smallAllocDelta;
void* newPtr = nullptr;
if (nsize == 0)
free(ptr);
else
{
newPtr = realloc(ptr, nsize);
if (!newPtr)
{
Log(Debug::Error) << "Lua realloc " << osize << "->" << nsize << " failed";
smallAllocDelta = 0;
bigAllocDelta = 0;
}
}
self->mTotalMemoryUsage += smallAllocDelta + bigAllocDelta;
self->mSmallAllocMemoryUsage += smallAllocDelta;
if (bigAllocDelta != 0)
{