diff options
author | Carl Lerche <me@carllerche.com> | 2015-10-16 14:18:06 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-10-16 14:18:10 -0700 |
commit | cebc5b801090089434a11e27045b00fd9da84346 (patch) | |
tree | 9af95979675e0fd37fc4a656e8cde962971fd683 /src | |
parent | 2cc0603942b5841db7c1bb93bb642bafa471e93a (diff) | |
download | nix-cebc5b801090089434a11e27045b00fd9da84346.zip |
Fix memory issue with exec family of fns
Diffstat (limited to 'src')
-rw-r--r-- | src/unistd.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 567b939e..5af84c93 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -167,13 +167,13 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> { return Ok(()) } -fn to_exec_array(args: &[CString]) -> *const *const c_char { +fn to_exec_array(args: &[CString]) -> Vec<*const c_char> { use std::ptr; use libc::c_char; let mut args_p: Vec<*const c_char> = args.iter().map(|s| s.as_ptr()).collect(); args_p.push(ptr::null()); - args_p.as_ptr() + args_p } #[inline] @@ -181,7 +181,7 @@ pub fn execv(path: &CString, argv: &[CString]) -> Result<()> { let args_p = to_exec_array(argv); unsafe { - ffi::execv(path.as_ptr(), args_p) + ffi::execv(path.as_ptr(), args_p.as_ptr()) }; Err(Error::Sys(Errno::last())) @@ -193,7 +193,7 @@ pub fn execve(path: &CString, args: &[CString], env: &[CString]) -> Result<()> { let env_p = to_exec_array(env); unsafe { - ffi::execve(path.as_ptr(), args_p, env_p) + ffi::execve(path.as_ptr(), args_p.as_ptr(), env_p.as_ptr()) }; Err(Error::Sys(Errno::last())) @@ -204,7 +204,7 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<()> { let args_p = to_exec_array(args); unsafe { - ffi::execvp(filename.as_ptr(), args_p) + ffi::execvp(filename.as_ptr(), args_p.as_ptr()) }; Err(Error::Sys(Errno::last())) |