From e2d894a10f1ac9784ada71ab8cd5c74a3a59e98e Mon Sep 17 00:00:00 2001 From: Nameless Date: Thu, 19 Dec 2024 08:40:54 -0600 Subject: [PATCH 1/2] move luv_work_cleanup into loop gc atexit may be called after luv is unloaded and will segfault. --- src/luv.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/luv.c b/src/luv.c index 18c01936..cb9c1c7c 100644 --- a/src/luv.c +++ b/src/luv.c @@ -838,6 +838,11 @@ static int loop_gc(lua_State *L) { while (uv_loop_close(loop)) { uv_run(loop, UV_RUN_DEFAULT); } + /* do cleanup in main thread */ + lua_getglobal(L, "_THREAD"); + if (lua_isnil(L, -1)) + luv_work_cleanup(); + lua_pop(L, 1); return 0; } @@ -885,12 +890,6 @@ LUALIB_API int luaopen_luv (lua_State* L) { if (ret < 0) { return luaL_error(L, "%s: %s\n", uv_err_name(ret), uv_strerror(ret)); } - - /* do cleanup in main thread */ - lua_getglobal(L, "_THREAD"); - if (lua_isnil(L, -1)) - atexit(luv_work_cleanup); - lua_pop(L, 1); } // pcall is NULL, luv use default callback routine if (ctx->cb_pcall==NULL) { From 2168f2cabe09ca35f66f0a455aa160268650df18 Mon Sep 17 00:00:00 2001 From: Nameless Date: Thu, 19 Dec 2024 08:41:23 -0600 Subject: [PATCH 2/2] asan: fix mismatched function pointer type --- src/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test.c b/src/test.c index cf719f52..80c1316d 100644 --- a/src/test.c +++ b/src/test.c @@ -63,7 +63,7 @@ static lua_State *vm_acquire(uv_loop_t* loop) { static void vm_release(lua_State* L) { lua_close(L); } -static lua_State* luv_thread_acquire_vm() { +static lua_State* luv_thread_acquire_vm(void) { lua_State* L = vm_acquire(NULL); /* create state */ lua_pushboolean(L, 1);