 +        &p->fstderr, &error)) {
 +    p->cstdout = new_channel(p->fstdout, p, p->stdout_cb > 0);
 +    p->cstderr = new_channel(p->fstderr, p, p->stderr_cb > 0);
-+    if (p->exit_cb != LUA_REFNIL)
-+      g_child_watch_add_full(
-+        G_PRIORITY_DEFAULT + 1, p->pid, proc_exited, p, NULL);
++    g_child_watch_add(p->pid, proc_exited, p);
 +    lua_pushnil(L); // no error
 +  } else {
 +    lua_pushnil(L);

 #endif			/* } */
 
 
--- a/src/loslib.c	2020-11-13 10:32:01.000000000 -0500
+++ b/src/loslib.c	2022-02-18 16:17:50.639380353 -0500
@@ -4,6 +4,15 @@
 ** See Copyright Notice in lua.h
 */

+    p->fstdin = proc_stdin, p->fstdout = proc_stdout, p->fstderr = proc_stderr;
+    p->cstdout = new_channel(FD(proc_stdout), p, p->stdout_cb > 0);
+    p->cstderr = new_channel(FD(proc_stderr), p, p->stderr_cb > 0);
+    g_child_watch_add(p->pid, proc_exited, p);
+    // Close unneeded handles.
+    CloseHandle(proc_info.hThread);
+    CloseHandle(stdin_read);
