Skip to content

Commit

Permalink
Merge branch 'realloc' into 'master'
Browse files Browse the repository at this point in the history
Don't assume realloc always succeeds

See merge request OpenMW/openmw!4331
  • Loading branch information
jvoisin committed Aug 23, 2024
2 parents 3c0353e + aa808d6 commit 830a26f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/lua/luastate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 830a26f

Please sign in to comment.