prevent accidental double free by checking tag before drop

This commit is contained in:
Bennet Bleßmann
2024-08-03 19:36:05 +02:00
parent 4d3ceb387e
commit 9e8d8aa19e

View File

@@ -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