diff --git a/src/sb_lua.c b/src/sb_lua.c index 3332fd70e..1babcb8ac 100644 --- a/src/sb_lua.c +++ b/src/sb_lua.c @@ -828,9 +828,6 @@ int sb_lua_close_state(lua_State *state) { sb_lua_ctxt_t * const ctxt = &tls_lua_ctxt; - if (state != NULL) - lua_close(state); - if (ctxt != NULL) { sb_lua_db_disconnect(state); @@ -842,6 +839,9 @@ int sb_lua_close_state(lua_State *state) } } + if (state != NULL) + lua_close(state); + ctxt->L = NULL; return 0;