1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-26 12:14:54 +00:00

Merge branch 'realloc' into 'master'

Don't assume realloc always succeeds

See merge request OpenMW/openmw!4331
This commit is contained in:
jvoisin 2024-08-23 10:34:38 +00:00
commit 830a26f75e

View File

@ -101,14 +101,21 @@ 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";
return nullptr;
}
}
self->mTotalMemoryUsage += smallAllocDelta + bigAllocDelta;
self->mSmallAllocMemoryUsage += smallAllocDelta;
if (bigAllocDelta != 0)
{