diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-09-16 21:07:02 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-09-16 21:07:02 -0400 |
| commit | a9ecb26c34d77f616fb029af3d09ffd69b9aa178 (patch) | |
| tree | 0c35cab36312b62a02a554e0a16f938d7b26d5b8 /std | |
| parent | 21a55d89b6f14f03c905220ce174bc72cd6a91b0 (diff) | |
| download | zig-a9ecb26c34d77f616fb029af3d09ffd69b9aa178.tar.gz zig-a9ecb26c34d77f616fb029af3d09ffd69b9aa178.zip | |
std.os.ChildProcess: fix fd leak
Diffstat (limited to 'std')
| -rw-r--r-- | std/os/child_process.zig | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/std/os/child_process.zig b/std/os/child_process.zig index 3f3ddf03bf..0dfdc08e80 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 { |
