commit a9ecb26c34d77f616fb029af3d09ffd69b9aa178 (tree)
parent 21a55d89b6f14f03c905220ce174bc72cd6a91b0
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Sat, 16 Sep 2017 21:07:02 -0400
std.os.ChildProcess: fix fd leak
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git 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 {