about summary refs log tree commit diff
path: root/src/liballoc/tests
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2019-12-13 21:34:30 +0100
committerJonas Schievink <jonasschievink@gmail.com>2020-01-19 20:24:08 +0100
commit163ed23f0081d7283ccaef39141bc29879260663 (patch)
tree189f3915e9c58458d872e1711282f81e8334ad2a /src/liballoc/tests
parentb04ca13873d5ef5e5b18195aaf8925562302e8e0 (diff)
Fix leak in vec::IntoIter when a destructor panics
Diffstat (limited to 'src/liballoc/tests')
-rw-r--r--src/liballoc/tests/vec.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs
index 80acba0a3a1..2a027fd5d2b 100644
--- a/src/liballoc/tests/vec.rs
+++ b/src/liballoc/tests/vec.rs
@@ -766,6 +766,35 @@ fn test_into_iter_clone() {
 }
 
 #[test]
+fn test_into_iter_leak() {
+    static mut DROPS: i32 = 0;
+
+    struct D(bool);
+
+    impl Drop for D {
+        fn drop(&mut self) {
+            unsafe {
+                DROPS += 1;
+            }
+
+            if self.0 {
+                panic!("panic in `drop`");
+            }
+        }
+    }
+
+    let v = vec![
+        D(false),
+        D(true),
+        D(false),
+    ];
+
+    catch_unwind(move || drop(v.into_iter())).ok();
+
+    assert_eq!(unsafe { DROPS }, 3);
+}
+
+#[test]
 fn test_cow_from() {
     let borrowed: &[_] = &["borrowed", "(slice)"];
     let owned = vec!["owned", "(vec)"];