From f19558f2fbd053c17b9caefe36bdc7fb14dc83bf Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 21 Oct 2020 01:33:09 +0000 Subject: [PATCH] skiplist: Fix undefined behavior in arena drop The Vec must be deallocated with the same pointer alignment and capacity as it is created. Signed-off-by: Brian Anderson --- skiplist/src/arena.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/skiplist/src/arena.rs b/skiplist/src/arena.rs index 5f03bfe1..10c7e6cf 100644 --- a/skiplist/src/arena.rs +++ b/skiplist/src/arena.rs @@ -11,7 +11,9 @@ struct ArenaCore { impl Drop for ArenaCore { fn drop(&mut self) { unsafe { - Vec::from_raw_parts(self.ptr, 0, self.cap); + let ptr = self.ptr as *mut u64; + let cap = self.cap / 8; + Vec::from_raw_parts(ptr, 0, cap); } } }