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,8 +305,10 @@ 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) {
self.set_tag(ArenaHeaderTag::Dropped); if self.get_tag() != ArenaHeaderTag::Dropped {
unsafe { ManuallyDrop::drop(&mut *self.as_ptr()) } self.set_tag(ArenaHeaderTag::Dropped);
unsafe { ManuallyDrop::drop(&mut *self.as_ptr()) }
}
} }
} }