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 {...@@ -65,6 +65,7 @@ pub const ChildProcess = struct {
65 defer restore_SIGCHLD();65 defer restore_SIGCHLD();
6666
67 if (self.term) |term| {67 if (self.term) |term| {
68 self.cleanupStreams();
68 return term;69 return term;
69 }70 }
70 const ret = posix.kill(self.pid, posix.SIGTERM);71 const ret = posix.kill(self.pid, posix.SIGTERM);
...@@ -87,6 +88,7 @@ pub const ChildProcess = struct {...@@ -87,6 +88,7 @@ pub const ChildProcess = struct {
87 defer restore_SIGCHLD();88 defer restore_SIGCHLD();
8889
89 if (self.term) |term| {90 if (self.term) |term| {
91 self.cleanupStreams();
90 return term;92 return term;
91 }93 }
9294
...@@ -119,9 +121,9 @@ pub const ChildProcess = struct {...@@ -119,9 +121,9 @@ pub const ChildProcess = struct {
119 }121 }
120122
121 fn cleanupStreams(self: &ChildProcess) {123 fn cleanupStreams(self: &ChildProcess) {
122 if (self.stdin) |stdin| { stdin.close(); self.allocator.free(stdin); }124 if (self.stdin) |stdin| { stdin.close(); self.allocator.free(stdin); self.stdin = null; }
123 if (self.stdout) |stdout| { stdout.close(); self.allocator.free(stdout); }125 if (self.stdout) |stdout| { stdout.close(); self.allocator.free(stdout); self.stdout = null; }
124 if (self.stderr) |stderr| { stderr.close(); self.allocator.free(stderr); }126 if (self.stderr) |stderr| { stderr.close(); self.allocator.free(stderr); self.stderr = null; }
125 }127 }
126128
127 fn cleanupAfterWait(self: &ChildProcess, status: i32) -> %Term {129 fn cleanupAfterWait(self: &ChildProcess, status: i32) -> %Term {