Skip to content

Commit e0c9719

Browse files
committed
Avoid a double drop in Vec::dedup if a destructor panics
1 parent 13bf0b2 commit e0c9719

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/alloc/src/vec/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,8 @@ impl<T, A: Allocator> Vec<T, A> {
16191619
let prev_ptr = ptr.add(gap.write.wrapping_sub(1));
16201620

16211621
if same_bucket(&mut *read_ptr, &mut *prev_ptr) {
1622+
// Increase `gap.read` now since the drop may panic.
1623+
gap.read += 1;
16221624
/* We have found duplicate, drop it in-place */
16231625
ptr::drop_in_place(read_ptr);
16241626
} else {
@@ -1631,9 +1633,8 @@ impl<T, A: Allocator> Vec<T, A> {
16311633

16321634
/* We have filled that place, so go further */
16331635
gap.write += 1;
1636+
gap.read += 1;
16341637
}
1635-
1636-
gap.read += 1;
16371638
}
16381639

16391640
/* Technically we could let `gap` clean up with its Drop, but

0 commit comments

Comments
 (0)