Skip to content

Commit 9c442bb

Browse files
committed
---
yaml --- r: 4002 b: refs/heads/master c: a14e5e7 h: refs/heads/master v: v3
1 parent 170316f commit 9c442bb

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a33bc56e43adbdfce78c63337c175053038f3362
2+
refs/heads/master: a14e5e70462fed497ce8e12e52c1ef099678a8de

trunk/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)