1
Fork 0

Don't forget to close executable file

This commit is contained in:
Jeremy Soller 2018-08-16 18:47:52 -06:00 committed by jD91mZM2
parent b400005861
commit 8c277d843c
No known key found for this signature in database
GPG key ID: 3055D54729A72666

View file

@ -318,7 +318,7 @@ impl Command {
}; };
let fd = if let Some(program) = program { let fd = if let Some(program) = program {
t!(cvt(syscall::open(program.as_os_str().as_bytes(), syscall::O_RDONLY))) t!(cvt(syscall::open(program.as_os_str().as_bytes(), syscall::O_RDONLY | syscall::O_CLOEXEC)))
} else { } else {
return io::Error::from_raw_os_error(syscall::ENOENT); return io::Error::from_raw_os_error(syscall::ENOENT);
}; };
@ -341,6 +341,7 @@ impl Command {
} }
if let Err(err) = syscall::fexec(fd, &args, &vars) { if let Err(err) = syscall::fexec(fd, &args, &vars) {
let _ = syscall::close(fd);
io::Error::from_raw_os_error(err.errno as i32) io::Error::from_raw_os_error(err.errno as i32)
} else { } else {
panic!("return from exec without err"); panic!("return from exec without err");