about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-05-26 13:32:06 +0200
committerGitHub <noreply@github.com>2021-05-26 13:32:06 +0200
commit27899e3887c1e7c767b51ca5ee5e88ac4a543687 (patch)
tree8d51c2ab81bc1e9b7c6753b4eaaea07cf942b8b2 /library/alloc/src
parent69c78a98ee2fb1e96675beb50115495bffca9777 (diff)
parentc9595faa2850b01966c64682d2bb8b32e0955625 (diff)
downloadrust-27899e3887c1e7c767b51ca5ee5e88ac4a543687.tar.gz
rust-27899e3887c1e7c767b51ca5ee5e88ac4a543687.zip
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
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/vec/mod.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs
index 1c33ff555d6..105c60e7bf0 100644
--- a/library/alloc/src/vec/mod.rs
+++ b/library/alloc/src/vec/mod.rs
@@ -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