memory_manager: use MFD_CLOEXEC flag when creating memory fd
Until there is a need for sharing the memory fd with a child process, we
should err on the safe side to close it on exec.
@@ -1252,9 +1252,8 @@ impl MemoryManager {
}
}
None => {
- let fd = Self::memfd_create(
- &ffi::CString::new("ch_ram").unwrap(),
- if hugepages {
+ let flags = libc::MFD_CLOEXEC
+ | if hugepages {
libc::MFD_HUGETLB
| if let Some(hugepage_size) = hugepage_size {
/*
@@ -1274,8 +1273,8 @@ impl MemoryManager {
}
} else {
0
- },
- )
+ };
+ let fd = Self::memfd_create(&ffi::CString::new("ch_ram").unwrap(), flags)
.map_err(Error::SharedFileCreate)?;
let f = unsafe { File::from_raw_fd(fd) };
