Skip to content

Commit a14e5e7

Browse files
committed
Avoid double-closing pipes in std::run::start_program
Linux and mac seem fine with it, Windows does not
1 parent a33bc56 commit a14e5e7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lib/run_program.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn start_program(str prog, vec[str] args) -> @program {
5050
os::libc::close(pipe_input._0);
5151
os::libc::close(pipe_output._1);
5252
obj new_program(int pid,
53-
int in_fd,
53+
mutable int in_fd,
5454
os::libc::FILE out_file,
5555
mutable bool finished) {
5656
fn get_id() -> int { ret pid; }
@@ -60,14 +60,23 @@ fn start_program(str prog, vec[str] args) -> @program {
6060
fn output() -> io::reader {
6161
ret io::new_reader(io::FILE_buf_reader(out_file, false));
6262
}
63-
fn close_input() { os::libc::close(in_fd); }
63+
fn close_input() {
64+
auto invalid_fd = -1;
65+
if (in_fd != invalid_fd) {
66+
os::libc::close(in_fd);
67+
in_fd = invalid_fd;
68+
}
69+
}
6470
fn finish() -> int {
6571
if (finished) { ret 0; }
6672
finished = true;
67-
os::libc::close(in_fd);
73+
self.close_input();
6874
ret os::waitpid(pid);
6975
}drop {
70-
if (!finished) { os::libc::close(in_fd); os::waitpid(pid); }
76+
self.close_input();
77+
if (!finished) {
78+
os::waitpid(pid);
79+
}
7180
os::libc::fclose(out_file);
7281
}
7382
}

0 commit comments

Comments
 (0)