mirror of
https://github.com/openharmony/third_party_rust_mio.git
synced 2026-06-30 20:58:01 -04:00
Fix possible fd leak in kqueue creation
This commit is contained in:
@@ -63,15 +63,17 @@ pub struct Selector {
|
||||
|
||||
impl Selector {
|
||||
pub fn new() -> io::Result<Selector> {
|
||||
syscall!(kqueue())
|
||||
.and_then(|kq| syscall!(fcntl(kq, libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| kq))
|
||||
.map(|kq| Selector {
|
||||
#[cfg(debug_assertions)]
|
||||
id: NEXT_ID.fetch_add(1, Ordering::Relaxed),
|
||||
kq,
|
||||
#[cfg(debug_assertions)]
|
||||
has_waker: AtomicBool::new(false),
|
||||
})
|
||||
let kq = syscall!(kqueue())?;
|
||||
let selector = Selector {
|
||||
#[cfg(debug_assertions)]
|
||||
id: NEXT_ID.fetch_add(1, Ordering::Relaxed),
|
||||
kq,
|
||||
#[cfg(debug_assertions)]
|
||||
has_waker: AtomicBool::new(false),
|
||||
};
|
||||
|
||||
syscall!(fcntl(kq, libc::F_SETFD, libc::FD_CLOEXEC))?;
|
||||
Ok(selector)
|
||||
}
|
||||
|
||||
pub fn try_clone(&self) -> io::Result<Selector> {
|
||||
|
||||
Reference in New Issue
Block a user