Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Do not panic when failing to release resources in Drop impls. #32

Merged
merged 1 commit into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,12 @@ impl Drop for MmapInner {
let alignment = self.ptr as usize % page_size();
let len = self.len + alignment;
let len = len.max(1);
// Any errors during unmapping/closing are ignored as the only way
// to report them would be through panicking which is highly discouraged
// in Drop impls, c.f. https://github.com/rust-lang/lang-team/issues/97
unsafe {
let ptr = self.ptr.offset(-(alignment as isize));
assert!(
libc::munmap(ptr, len as libc::size_t) == 0,
"unable to unmap mmap: {}",
io::Error::last_os_error()
);
libc::munmap(ptr, len as libc::size_t);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,12 @@ impl Drop for MmapInner {
return;
}
let alignment = self.ptr as usize % allocation_granularity();
// Any errors during unmapping/closing are ignored as the only way
// to report them would be through panicking which is highly discouraged
// in Drop impls, c.f. https://github.com/rust-lang/lang-team/issues/97
unsafe {
let ptr = self.ptr.offset(-(alignment as isize));
assert!(
UnmapViewOfFile(ptr) != 0,
"unable to unmap mmap: {}",
io::Error::last_os_error()
);
UnmapViewOfFile(ptr);

if let Some(handle) = self.handle {
CloseHandle(handle);
Expand Down