@@ -439,11 +439,9 @@ fn make_argv(prog: &CString, args: &[CString])
439
439
{
440
440
let mut ptrs: Vec < * const libc:: c_char > = Vec :: with_capacity ( args. len ( ) +1 ) ;
441
441
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.
447
445
ptrs. push ( prog. as_ptr ( ) ) ;
448
446
ptrs. extend ( args. iter ( ) . map ( |tmp| tmp. as_ptr ( ) ) ) ;
449
447
@@ -457,10 +455,9 @@ fn make_envp(env: Option<&HashMap<OsString, OsString>>)
457
455
-> ( * const c_void , Vec < Vec < u8 > > , Vec < * const libc:: c_char > )
458
456
{
459
457
// 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.
464
461
if let Some ( env) = env {
465
462
let mut tmps = Vec :: with_capacity ( env. len ( ) ) ;
466
463
0 commit comments