Fix an invalid memory access in run_program and friends
This commit is contained in:
parent
a0ab57b3f6
commit
fb9a117743
@ -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);
|
||||
|
15
src/test/run-pass/lib-run.rs
Normal file
15
src/test/run-pass/lib-run.rs
Normal 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user