From 314c6057b785cd94ac88905ccfce61724107d66b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 6 Jul 2020 14:06:47 -0300 Subject: Avoid any code before locks in the API For consistency in the C API, avoid any initializations before callling lua_lock. --- lstate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index b1f487ff..28853dc7 100644 --- a/lstate.c +++ b/lstate.c @@ -318,9 +318,10 @@ static void close_state (lua_State *L) { LUA_API lua_State *lua_newthread (lua_State *L) { - global_State *g = G(L); + global_State *g; lua_State *L1; lua_lock(L); + g = G(L); luaC_checkGC(L); /* create new thread */ L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l; @@ -437,8 +438,8 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { LUA_API void lua_close (lua_State *L) { - L = G(L)->mainthread; /* only the main thread can be closed */ lua_lock(L); + L = G(L)->mainthread; /* only the main thread can be closed */ close_state(L); } -- cgit v1.2.3-55-g6feb