Rollup merge of #85625 - SkiFire13:fix-85613-vec-dedup-drop-panics, r=nagisa

Prevent double drop in `Vec::dedup_by` if a destructor panics

Fixes #85613
This commit is contained in:
Dylan DPC
2021-05-26 13:32:06 +02:00
committed by GitHub
2 changed files with 28 additions and 25 deletions

View File

@@ -1619,6 +1619,8 @@ impl<T, A: Allocator> Vec<T, A> {
let prev_ptr = ptr.add(gap.write.wrapping_sub(1));
if same_bucket(&mut *read_ptr, &mut *prev_ptr) {
// Increase `gap.read` now since the drop may panic.
gap.read += 1;
/* We have found duplicate, drop it in-place */
ptr::drop_in_place(read_ptr);
} else {
@@ -1631,9 +1633,8 @@ impl<T, A: Allocator> Vec<T, A> {
/* We have filled that place, so go further */
gap.write += 1;
gap.read += 1;
}
gap.read += 1;
}
/* Technically we could let `gap` clean up with its Drop, but