From 51e4d814fb409f08d0f41f31b9490aed5a506a5e Mon Sep 17 00:00:00 2001 From: Alexander Qi Date: Wed, 30 Aug 2023 00:10:59 +0800 Subject: [PATCH] bolts: Fix shmem leak when Drop-ing CommonUnixShMem (#1484) --- libafl_bolts/src/shmem.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libafl_bolts/src/shmem.rs b/libafl_bolts/src/shmem.rs index 940544747d..87cb6f6f9f 100644 --- a/libafl_bolts/src/shmem.rs +++ b/libafl_bolts/src/shmem.rs @@ -623,7 +623,7 @@ pub mod unix_shmem { use libc::{ 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::{ @@ -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)] impl Drop for CommonUnixShMem { fn drop(&mut self) { unsafe { let id_int: i32 = self.id.into(); shmctl(id_int, libc::IPC_RMID, ptr::null_mut()); + + shmdt(self.map as *mut _); } } }