fix(wayland/shm): don't leak fds on shm pool destruction
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -5,16 +5,17 @@ use crate::wayland::{
|
|||||||
};
|
};
|
||||||
use memmap2::{MmapOptions, RemapOptions};
|
use memmap2::{MmapOptions, RemapOptions};
|
||||||
use parking_lot::{Mutex, MutexGuard, RawMutex, lock_api::MappedMutexGuard};
|
use parking_lot::{Mutex, MutexGuard, RawMutex, lock_api::MappedMutexGuard};
|
||||||
use waynest_server::Client as _;
|
use std::os::fd::{AsRawFd, OwnedFd};
|
||||||
use std::os::fd::{IntoRawFd, OwnedFd};
|
|
||||||
use waynest::ObjectId;
|
use waynest::ObjectId;
|
||||||
use waynest_protocols::server::core::wayland::wl_shm::Format;
|
use waynest_protocols::server::core::wayland::wl_shm::Format;
|
||||||
pub use waynest_protocols::server::core::wayland::wl_shm_pool::*;
|
pub use waynest_protocols::server::core::wayland::wl_shm_pool::*;
|
||||||
|
use waynest_server::Client as _;
|
||||||
|
|
||||||
#[derive(Debug, waynest_server::RequestDispatcher)]
|
#[derive(Debug, waynest_server::RequestDispatcher)]
|
||||||
#[waynest(error = crate::wayland::WaylandError, connection = crate::wayland::Client)]
|
#[waynest(error = crate::wayland::WaylandError, connection = crate::wayland::Client)]
|
||||||
pub struct ShmPool {
|
pub struct ShmPool {
|
||||||
inner: Mutex<memmap2::MmapMut>,
|
inner: Mutex<memmap2::MmapMut>,
|
||||||
|
fd: OwnedFd,
|
||||||
id: ObjectId,
|
id: ObjectId,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,11 +25,12 @@ impl ShmPool {
|
|||||||
let map = unsafe {
|
let map = unsafe {
|
||||||
MmapOptions::new()
|
MmapOptions::new()
|
||||||
.len(size as usize)
|
.len(size as usize)
|
||||||
.map_mut(fd.into_raw_fd())?
|
.map_mut(fd.as_raw_fd())?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
inner: Mutex::new(map),
|
inner: Mutex::new(map),
|
||||||
|
fd,
|
||||||
id,
|
id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user