about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe8472 <git@infinite-source.de>2021-04-02 23:06:05 +0200
committerThe8472 <git@infinite-source.de>2021-04-04 01:37:05 +0200
commit3bd241f95b6992d73f159c00551069e2c3424747 (patch)
tree58ce6ab6ae75a892e8063e71837eb4afaa85e25b
parent97717a561844eccbb6d6cc114adb94a8fa4e0172 (diff)
downloadrust-3bd241f95b6992d73f159c00551069e2c3424747.tar.gz
rust-3bd241f95b6992d73f159c00551069e2c3424747.zip
cleanup leak after test to make miri happy
-rw-r--r--library/alloc/tests/vec.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs
index b926c697d58..026d3f63bb7 100644
--- a/library/alloc/tests/vec.rs
+++ b/library/alloc/tests/vec.rs
@@ -1078,12 +1078,21 @@ fn test_from_iter_specialization_panic_during_drop_leaks() {
         }
     }
 
+    let mut to_free: *mut Droppable = core::ptr::null_mut();
+    let mut cap = 0;
+
     let _ = std::panic::catch_unwind(AssertUnwindSafe(|| {
-        let v = vec![Droppable::DroppedTwice(Box::new(123)), Droppable::PanicOnDrop];
+        let mut v = vec![Droppable::DroppedTwice(Box::new(123)), Droppable::PanicOnDrop];
+        to_free = v.as_mut_ptr();
+        cap = v.capacity();
         let _ = v.into_iter().take(0).collect::<Vec<_>>();
     }));
 
     assert_eq!(unsafe { DROP_COUNTER }, 1);
+    // clean up the leak to keep miri happy
+    unsafe {
+        Vec::from_raw_parts(to_free, 0, cap);
+    }
 }
 
 #[test]