summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/luaengine.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2017-07-15 18:06:07 +1000
committer Vas Crabb <vas@vastheman.com>2017-07-15 18:06:29 +1000
commitc4f354a7a35610c9a5fe116cc27bfa789f916265 (patch)
tree3a1452eef74d2301e071eb66ebbacbce35250ff2 /src/frontend/mame/luaengine.cpp
parent166050c2ef64357f647e7202ad82aee132afea26 (diff)
lua engine: safer cleanup, fix leak (nw)
Diffstat (limited to 'src/frontend/mame/luaengine.cpp')
-rw-r--r--src/frontend/mame/luaengine.cpp11
1 files changed, 8 insertions, 3 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<sol::state_view>(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)