Skip to content

Commit 73854b1

Browse files
committed
sys/unix/process.rs: Update comments in make_argv and make_envp
The implementation changed in 33a2191, but the comments did not change to match.
1 parent 0486e12 commit 73854b1

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/libstd/sys/unix/process.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,9 @@ fn make_argv(prog: &CString, args: &[CString])
439439
{
440440
let mut ptrs: Vec<*const libc::c_char> = Vec::with_capacity(args.len()+1);
441441

442-
// Convert the CStrings into an array of pointers. Note: the
443-
// lifetime of the various CStrings involved is guaranteed to be
444-
// larger than the lifetime of our invocation of cb, but this is
445-
// technically unsafe as the callback could leak these pointers
446-
// out of our scope.
442+
// Convert the CStrings into an array of pointers. Also return the
443+
// vector that owns the raw pointers, to ensure they live long
444+
// enough.
447445
ptrs.push(prog.as_ptr());
448446
ptrs.extend(args.iter().map(|tmp| tmp.as_ptr()));
449447

@@ -457,10 +455,9 @@ fn make_envp(env: Option<&HashMap<OsString, OsString>>)
457455
-> (*const c_void, Vec<Vec<u8>>, Vec<*const libc::c_char>)
458456
{
459457
// On posixy systems we can pass a char** for envp, which is a
460-
// null-terminated array of "k=v\0" strings. Since we must create
461-
// these strings locally, yet expose a raw pointer to them, we
462-
// create a temporary vector to own the CStrings that outlives the
463-
// call to cb.
458+
// null-terminated array of "k=v\0" strings. As with make_argv, we
459+
// return two vectors that own the data to ensure that they live
460+
// long enough.
464461
if let Some(env) = env {
465462
let mut tmps = Vec::with_capacity(env.len());
466463

0 commit comments

Comments
 (0)