From c4f354a7a35610c9a5fe116cc27bfa789f916265 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sat, 15 Jul 2017 18:06:07 +1000 Subject: lua engine: safer cleanup, fix leak (nw) --- src/frontend/mame/luaengine.cpp | 11 ++++++++--- src/frontend/mame/luaengine.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index bc92f4b3c9f..a7bfd10114e 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -542,7 +542,7 @@ lua_engine::lua_engine() { m_machine = nullptr; m_lua_state = luaL_newstate(); /* create state */ - m_sol_state = new sol::state_view(m_lua_state); // create sol view + m_sol_state = std::make_unique(m_lua_state); // create sol view luaL_checkversion(m_lua_state); lua_gc(m_lua_state, LUA_GCSTOP, 0); /* stop collector during initialization */ @@ -1868,8 +1868,13 @@ bool lua_engine::frame_hook() void lua_engine::close() { - lua_settop(m_lua_state, 0); /* clear stack */ - lua_close(m_lua_state); + m_sol_state.reset(); + if (m_lua_state) + { + lua_settop(m_lua_state, 0); /* clear stack */ + lua_close(m_lua_state); + m_lua_state = nullptr; + } } void lua_engine::resume(void *ptr, int nparam) diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h index e3f8d5ee93d..d17a6eece18 100644 --- a/src/frontend/mame/luaengine.h +++ b/src/frontend/mame/luaengine.h @@ -110,7 +110,7 @@ public: private: // internal state lua_State *m_lua_state; - sol::state_view *m_sol_state; + std::unique_ptr m_sol_state; running_machine *m_machine; std::vector m_menu; -- cgit v1.2.3