Fix Heap::drop not accounting for null-initialized HeapInner
This commit is contained in:
@@ -24,17 +24,29 @@ pub struct Heap {
|
|||||||
|
|
||||||
impl Drop for Heap {
|
impl Drop for Heap {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
if !self.inner.ptr.is_null() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let layout = alloc::Layout::array::<u8>(self.inner.byte_cap).unwrap();
|
let layout = alloc::Layout::array::<u8>(self.inner.byte_cap).unwrap();
|
||||||
alloc::dealloc(self.inner.ptr, layout);
|
alloc::dealloc(self.inner.ptr, layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: verify the soundness of the various accesses to `ptr`,
|
||||||
|
// or rely on a Vec-like library with fallible allocations.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct InnerHeap {
|
struct InnerHeap {
|
||||||
ptr: *mut u8,
|
ptr: *mut u8,
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// Must be equal to zero when `ptr.is_null()`.
|
||||||
byte_len: usize,
|
byte_len: usize,
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// Must be equal to zero when `ptr.is_null()`.
|
||||||
byte_cap: usize,
|
byte_cap: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user