Skip to content

Commit 8f19b19

Browse files
authored
Do not panic when failing to release resources in Drop impls.
C.f. rust-lang/lang-team#97 for a general discussion on why this is undesirable.
1 parent 0632c6a commit 8f19b19

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Diff for: src/unix.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,12 @@ impl Drop for MmapInner {
243243
let alignment = self.ptr as usize % page_size();
244244
let len = self.len + alignment;
245245
let len = len.max(1);
246+
// Any errors during unmapping/closing are ignored as the only way
247+
// to report them would be through panicking which is highly discouraged
248+
// in Drop impls, c.f. https://github.com/rust-lang/lang-team/issues/97
246249
unsafe {
247250
let ptr = self.ptr.offset(-(alignment as isize));
248-
assert!(
249-
libc::munmap(ptr, len as libc::size_t) == 0,
250-
"unable to unmap mmap: {}",
251-
io::Error::last_os_error()
252-
);
251+
libc::munmap(ptr, len as libc::size_t);
253252
}
254253
}
255254
}

Diff for: src/windows.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,12 @@ impl Drop for MmapInner {
489489
return;
490490
}
491491
let alignment = self.ptr as usize % allocation_granularity();
492+
// Any errors during unmapping/closing are ignored as the only way
493+
// to report them would be through panicking which is highly discouraged
494+
// in Drop impls, c.f. https://github.com/rust-lang/lang-team/issues/97
492495
unsafe {
493496
let ptr = self.ptr.offset(-(alignment as isize));
494-
assert!(
495-
UnmapViewOfFile(ptr) != 0,
496-
"unable to unmap mmap: {}",
497-
io::Error::last_os_error()
498-
);
497+
UnmapViewOfFile(ptr);
499498

500499
if let Some(handle) = self.handle {
501500
CloseHandle(handle);

0 commit comments

Comments
 (0)