about summary refs log tree commit diff
path: root/src/lib/run_program.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-07-18 21:03:28 -0700
committerBrian Anderson <banderson@mozilla.com>2011-07-19 10:15:16 -0700
commitfb9a117743636ac41cf494dde6198c955270a67e (patch)
treee1a0027377d3e83936d752e7f580fea4258bb6e1 /src/lib/run_program.rs
parenta0ab57b3f62017c065c6f3ced67e4c35898b51a3 (diff)
downloadrust-fb9a117743636ac41cf494dde6198c955270a67e.tar.gz
rust-fb9a117743636ac41cf494dde6198c955270a67e.zip
Fix an invalid memory access in run_program and friends
Diffstat (limited to 'src/lib/run_program.rs')
-rw-r--r--src/lib/run_program.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lib/run_program.rs b/src/lib/run_program.rs
index 43103435b59..7ece83e70cf 100644
--- a/src/lib/run_program.rs
+++ b/src/lib/run_program.rs
@@ -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 @@ type program =
 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);