Fix an invalid memory access in run_program and friends

This commit is contained in:
Brian Anderson 2011-07-18 21:03:28 -07:00
parent a0ab57b3f6
commit fb9a117743
2 changed files with 23 additions and 4 deletions

View File

@ -14,9 +14,10 @@ fn arg_vec(str prog, vec[str] args) -> vec[sbuf] {
}
fn run_program(str prog, vec[str] args) -> int {
auto pid =
rustrt::rust_run_program(vec::buf[sbuf](arg_vec(prog, args)), 0, 0,
0);
// Note: we have to hold on to this vector reference while we hold a
// pointer to its buffer
auto argv = arg_vec(prog, args);
auto pid = rustrt::rust_run_program(vec::buf(argv), 0, 0, 0);
ret os::waitpid(pid);
}
@ -32,8 +33,11 @@ fn run_program(str prog, vec[str] args) -> int {
fn start_program(str prog, vec[str] args) -> @program {
auto pipe_input = os::pipe();
auto pipe_output = os::pipe();
// Note: we have to hold on to this vector reference while we hold a
// pointer to its buffer
auto argv = arg_vec(prog, args);
auto pid =
rustrt::rust_run_program(vec::buf[sbuf](arg_vec(prog, args)),
rustrt::rust_run_program(vec::buf(argv),
pipe_input._0, pipe_output._1, 0);
if (pid == -1) { fail; }
os::libc::close(pipe_input._0);

View File

@ -0,0 +1,15 @@
// xfail-stage0
use std;
import std::run;
// Regression test for memory leaks
fn test_leaks() {
run::run_program("echo", []);
run::start_program("echo", []);
run::program_output("echo", []);
}
fn main() {
test_leaks();
}