Closed
Description
In the following page there is something missing to handle ZSTs which leads to a UB
Line 1 in ddfa421
When Vec is dropped filled with ZSTs, I am getting the following error
error for object 0x1: pointer being freed was not allocated
and indeed we never allocate anything for ZSTs, just pointing to some dangling pointer that represent our ZST.
I suggest a tweak to our Drop trait in raw_vec
to handle this case where we deallocate only for T when size of T > 0:
impl<T> Drop for RawVec<T> {
fn drop(&mut self) {
if self.cap != 0 && std::mem::size_of::<T>() > 0 {
let layout = std::alloc::Layout::array::<T>(self.cap).unwrap();
unsafe {
std::alloc::dealloc(self.ptr.as_ptr() as *mut _, layout);
}
}
}
}
Please see PR for fix #425
Metadata
Metadata
Assignees
Labels
No labels