Skip to content

Commit 29daea9

Browse files
Shnatselbluss
authored andcommitted
Fix double-free for ZSTs with Drop in .extend()
1 parent 0ff49b9 commit 29daea9

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/arrayvec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
11371137
debug_assert_ne!(ptr, end_ptr);
11381138
if mem::size_of::<T>() != 0 {
11391139
ptr.write(elt);
1140+
} else {
1141+
// The ZST element has logically been moved into the vector.
1142+
// There is no memory to write, but dropping `elt` here would
1143+
// drop it once now and once again when the vector is dropped.
1144+
mem::forget(elt);
11401145
}
11411146
ptr = raw_ptr_add(ptr, 1);
11421147
guard.data += 1;

0 commit comments

Comments
 (0)