Prevent Lua from allocating all heap memory (Horus) (#4440)

* Fixes #4284: Prevent Lua from allocating all heap memory (Horus)
Lua bitmap functions cleanup and docs update
Added x or y < 0 check to drawBitmap()

* Proper float constant
This commit is contained in:
Damjan Adamic
2017-02-11 22:21:14 +01:00
committed by Bertrand Songis
parent be61e07939
commit e80c4c858e
8 changed files with 94 additions and 31 deletions
+22 -1
View File
@@ -165,7 +165,7 @@ void luaClose(lua_State ** L)
}
else {
// we can only disable Lua for the rest of the session
luaDisable();
if (*L == lsScripts) luaDisable();
}
UNPROTECT_LUA();
*L = NULL;
@@ -954,6 +954,27 @@ bool luaTask(event_t evt, uint8_t scriptType, bool allowLcdUsage)
return scriptWasRun;
}
void checkLuaMemoryUsage()
{
#if (LUA_MEM_MAX > 0)
uint32_t totalMemUsed = luaGetMemUsed(lsScripts);
#if defined(COLORLCD)
totalMemUsed += luaGetMemUsed(lsWidgets);
totalMemUsed += luaExtraMemoryUsage;
#endif
if (totalMemUsed > LUA_MEM_MAX) {
TRACE("checkLuaMemoryUsage(): max limit reached (%u), killing Lua", totalMemUsed);
// disable Lua scripts
luaClose(&lsScripts);
luaDisable();
#if defined(COLORLCD)
// disable widgets
luaClose(&lsWidgets);
#endif
}
#endif
}
uint32_t luaGetMemUsed(lua_State * L)
{
return L ? (lua_gc(L, LUA_GCCOUNT, 0) << 10) + lua_gc(L, LUA_GCCOUNTB, 0) : 0;