Skip to content

Commit

Permalink
Don't assume realloc always succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Assumeru committed Aug 20, 2024
1 parent 527fa05 commit 4652151
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions components/lua/luastate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 4652151

Please sign in to comment.