authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-16 21:07:02-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-16 21:07:02-04:00
loga9ecb26c34d77f616fb029af3d09ffd69b9aa178
tree0c35cab36312b62a02a554e0a16f938d7b26d5b8
parent21a55d89b6f14f03c905220ce174bc72cd6a91b0

std.os.ChildProcess: fix fd leak


1 files changed, 5 insertions(+), 3 deletions(-)

std/os/child_process.zig+5-3
......@@ -65,6 +65,7 @@ pub const ChildProcess = struct {
6565 defer restore_SIGCHLD();
6666
6767 if (self.term) |term| {
68 self.cleanupStreams();
6869 return term;
6970 }
7071 const ret = posix.kill(self.pid, posix.SIGTERM);
......@@ -87,6 +88,7 @@ pub const ChildProcess = struct {
8788 defer restore_SIGCHLD();
8889
8990 if (self.term) |term| {
91 self.cleanupStreams();
9092 return term;
9193 }
9294
......@@ -119,9 +121,9 @@ pub const ChildProcess = struct {
119121 }
120122
121123 fn cleanupStreams(self: &ChildProcess) {
122 if (self.stdin) |stdin| { stdin.close(); self.allocator.free(stdin); }
123 if (self.stdout) |stdout| { stdout.close(); self.allocator.free(stdout); }
124 if (self.stderr) |stderr| { stderr.close(); self.allocator.free(stderr); }
124 if (self.stdin) |stdin| { stdin.close(); self.allocator.free(stdin); self.stdin = null; }
125 if (self.stdout) |stdout| { stdout.close(); self.allocator.free(stdout); self.stdout = null; }
126 if (self.stderr) |stderr| { stderr.close(); self.allocator.free(stderr); self.stderr = null; }
125127 }
126128
127129 fn cleanupAfterWait(self: &ChildProcess, status: i32) -> %Term {