prevent accidental double free by checking tag before drop
This commit is contained in:
@@ -305,10 +305,12 @@ impl<T: ?Sized + ArenaAllocated> TypedArenaPtr<T> {
|
|||||||
|
|
||||||
impl<P, T: ?Sized + ArenaAllocated<Payload = ManuallyDrop<P>>> TypedArenaPtr<T> {
|
impl<P, T: ?Sized + ArenaAllocated<Payload = ManuallyDrop<P>>> TypedArenaPtr<T> {
|
||||||
pub fn drop_payload(&mut self) {
|
pub fn drop_payload(&mut self) {
|
||||||
|
if self.get_tag() != ArenaHeaderTag::Dropped {
|
||||||
self.set_tag(ArenaHeaderTag::Dropped);
|
self.set_tag(ArenaHeaderTag::Dropped);
|
||||||
unsafe { ManuallyDrop::drop(&mut *self.as_ptr()) }
|
unsafe { ManuallyDrop::drop(&mut *self.as_ptr()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: ?Sized + ArenaAllocated> TypedArenaPtr<T>
|
impl<T: ?Sized + ArenaAllocated> TypedArenaPtr<T>
|
||||||
where
|
where
|
||||||
|
|||||||
Reference in New Issue
Block a user