std.os.ChildProcess: fix fd leak

This commit is contained in:
Andrew Kelley 2017-09-16 21:07:02 -04:00
parent 21a55d89b6
commit a9ecb26c34

View File

@ -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 {