Skip to content

Commit a9f2e5d

Browse files
committed
Fix use-after-free when forcibly reloading the luv module
Closes #819
1 parent 8bc42e2 commit a9f2e5d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/luv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,12 @@ static int loop_gc(lua_State *L) {
859859
while (uv_loop_close(loop)) {
860860
uv_run(loop, UV_RUN_DEFAULT);
861861
}
862+
// Set the loop to NULL to allow for multiple calls
863+
// of luaopen_luv, e.g. requiring 'luv', then setting
864+
// package.loaded['luv'] to nil, and then requiring 'luv' again.
865+
// The context lives as long as the Lua state, so it's
866+
// possible it could be around for multiple loops.
867+
ctx->loop = NULL;
862868
return 0;
863869
}
864870

0 commit comments

Comments
 (0)