Skip to content

Commit

Permalink
move luv_work_cleanup into loop gc
Browse files Browse the repository at this point in the history
atexit may be called after luv is unloaded and will segfault.
  • Loading branch information
truemedian committed Dec 19, 2024
1 parent 3ff02c8 commit e2d894a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e2d894a

Please sign in to comment.