bolts: Fix shmem leak when Drop-ing CommonUnixShMem (#1484)
This commit is contained in:
parent
c91fc9a521
commit
51e4d814fb
@ -623,7 +623,7 @@ pub mod unix_shmem {
|
|||||||
|
|
||||||
use libc::{
|
use libc::{
|
||||||
c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, close, ftruncate, mmap, munmap,
|
c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, close, ftruncate, mmap, munmap,
|
||||||
perror, shm_open, shm_unlink, shmat, shmctl, shmget,
|
perror, shm_open, shm_unlink, shmat, shmctl, shmdt, shmget,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -971,13 +971,15 @@ pub mod unix_shmem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Drop`] implementation for [`UnixShMem`], which cleans up the mapping.
|
/// [`Drop`] implementation for [`UnixShMem`], which detaches the memory and cleans up the mapping.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl Drop for CommonUnixShMem {
|
impl Drop for CommonUnixShMem {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let id_int: i32 = self.id.into();
|
let id_int: i32 = self.id.into();
|
||||||
shmctl(id_int, libc::IPC_RMID, ptr::null_mut());
|
shmctl(id_int, libc::IPC_RMID, ptr::null_mut());
|
||||||
|
|
||||||
|
shmdt(self.map as *mut _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user