fix(piluaprogram): add destructor to close Lua state
luaL_newstate() allocates a Lua state (~2-4 MB with libraries) in the constructor, but there was no destructor to call lua_close(). Every PILuaProgram instance leaked its entire Lua state. Add ~PILuaProgram() that calls lua_close(PRIVATE->lua_state).
This commit is contained in:
@@ -30,6 +30,11 @@ PILuaProgram::PILuaProgram() {
|
||||
}
|
||||
|
||||
|
||||
PILuaProgram::~PILuaProgram() {
|
||||
lua_close(PRIVATE->lua_state);
|
||||
}
|
||||
|
||||
|
||||
bool PILuaProgram::load(const PIString & script) {
|
||||
int ret = luaL_dostring(PRIVATE->lua_state, script.dataUTF8());
|
||||
if (ret != 0) return false;
|
||||
|
||||
@@ -41,6 +41,10 @@ public:
|
||||
//! \~russian Создает объект Lua-программы и открывает стандартные библиотеки Lua.
|
||||
PILuaProgram();
|
||||
|
||||
//! \~english Closes the Lua state and releases all associated resources.
|
||||
//! \~russian Закрывает Lua state и освобождает все связанные ресурсы.
|
||||
~PILuaProgram();
|
||||
|
||||
//! \~english Loads and executes Lua source code from \a script.
|
||||
//! \~russian Загружает и выполняет исходный код Lua из \a script.
|
||||
bool load(const PIString & script);
|
||||
|
||||
Reference in New Issue
Block a user