server/pty.zig — reap uses WNOHANG but unconditionally sets pid to -1server/pty.zig — reap uses WNOHANG but unconditionally sets pid to -1File: src/server/pty.zig:176–181
Severity: MEDIUM
Status: ✅ FIXED — reap now only sets pid = -1 when waitpid returns > 0 (child reaped). If the child is still running, pid remains valid for future reap/kill.
pub fn reap(self: *Pty) void {
if (self.pid > 0) {
var status: c_int = 0;
_ = waitpid(self.pid, &status, 1); // WNOHANG
self.pid = -1;
}
}
WNOHANG returns 0 if the child hasn’t exited. The code ignores the return value and sets pid = -1 regardless. If the process is still running (e.g. a slow shutdown), it becomes an untracked zombie, and the pid could be reused by the OS, leading to reaping the wrong process later.