Closed
Description
The args
method is defined as follows.
pub fn args() -> Args {
let args = unsafe { (ARGS.load(Ordering::Relaxed) as *const ArgsStore).as_ref() };
if let Some(args) = args {
Args(args.iter())
} else {
Args([].iter())
}
}
Clean-up function is defined as follows;
pub unsafe fn cleanup() {
let args = ARGS.swap(0, Ordering::Relaxed);
if args != 0 {
drop(Box::<ArgsStore>::from_raw(args as _))
}
}
It is possible for another thread to use std::env::args()
while the main thread quits, and access already freed memory - assuming the following sequence of events.
// Secondary thread
let args = unsafe { (ARGS.load(Ordering::Relaxed) as *const ArgsStore).as_ref() };
// Main thread
{
let args = ARGS.swap(0, Ordering::Relaxed);
if args != 0 {
drop(Box::<ArgsStore>::from_raw(args as _))
}
}
// Secondary thread
if let Some(args) = args {
Args(args.iter())
}
This issue has been assigned to @Goirad via this comment.