Browse Source

FFI: Avoid dangling cts->L.

Reported by ZumiKua. #1405
Mike Pall 1 month ago
parent
commit
c94312d348
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/lj_state.c

+ 4 - 0
src/lj_state.c

@@ -304,6 +304,10 @@ lua_State *lj_state_new(lua_State *L)
 void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L)
 void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L)
 {
 {
   lua_assert(L != mainthread(g));
   lua_assert(L != mainthread(g));
+#if LJ_HASFFI
+  if (ctype_ctsG(g) && ctype_ctsG(g)->L == L)  /* Avoid dangling cts->L. */
+    ctype_ctsG(g)->L = mainthread(g);
+#endif
   lj_func_closeuv(L, tvref(L->stack));
   lj_func_closeuv(L, tvref(L->stack));
   lua_assert(gcref(L->openupval) == NULL);
   lua_assert(gcref(L->openupval) == NULL);
   lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
   lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);