diff --git a/std/os/child_process.zig b/std/os/child_process.zig index 3f3ddf03b..0dfdc08e8 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -65,6 +65,7 @@ pub const ChildProcess = struct { defer restore_SIGCHLD(); if (self.term) |term| { + self.cleanupStreams(); return term; } const ret = posix.kill(self.pid, posix.SIGTERM); @@ -87,6 +88,7 @@ pub const ChildProcess = struct { defer restore_SIGCHLD(); if (self.term) |term| { + self.cleanupStreams(); return term; } @@ -119,9 +121,9 @@ pub const ChildProcess = struct { } fn cleanupStreams(self: &ChildProcess) { - if (self.stdin) |stdin| { stdin.close(); self.allocator.free(stdin); } - if (self.stdout) |stdout| { stdout.close(); self.allocator.free(stdout); } - if (self.stderr) |stderr| { stderr.close(); self.allocator.free(stderr); } + if (self.stdin) |stdin| { stdin.close(); self.allocator.free(stdin); self.stdin = null; } + if (self.stdout) |stdout| { stdout.close(); self.allocator.free(stdout); self.stdout = null; } + if (self.stderr) |stderr| { stderr.close(); self.allocator.free(stderr); self.stderr = null; } } fn cleanupAfterWait(self: &ChildProcess, status: i32) -> %Term {