Skip to content

Commit

Permalink
Fixed: Incorrect drop of memory mapped file due to lack of null termi…
Browse files Browse the repository at this point in the history
…nator.
  • Loading branch information
Sewer56 committed Jun 24, 2024
1 parent d6eed89 commit ccf1000
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src-rust/src/internal/memory_mapped_file_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use alloc::string::String;
#[cfg(not(feature = "no_format"))]
use errno::errno;

use libc::c_char;
use libc::mkdir;
use libc::stat;
use libc::S_IFDIR;
Expand Down Expand Up @@ -156,8 +155,11 @@ impl Drop for UnixMemoryMappedFile {
let _ = unsafe { munmap(self.data as *mut c_void, self.length) };
unsafe { close(self.file_descriptor) };
if !self.already_existed {
unsafe {
libc::unlink(self.file_path.as_ptr() as *const c_char);
// Create a null-terminated C string
if let Ok(file_path_cstr) = CString::new(self.file_path.as_str()) {
unsafe {
libc::unlink(file_path_cstr.as_ptr());
}
}
}
}
Expand Down

0 comments on commit ccf1000

Please sign in to comment.