From 3bd241f95b6992d73f159c00551069e2c3424747 Mon Sep 17 00:00:00 2001 From: The8472 Date: Fri, 2 Apr 2021 23:06:05 +0200 Subject: [PATCH 1/2] cleanup leak after test to make miri happy --- library/alloc/tests/vec.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index b926c697d58ab..026d3f63bb77a 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::>(); })); assert_eq!(unsafe { DROP_COUNTER }, 1); + // clean up the leak to keep miri happy + unsafe { + Vec::from_raw_parts(to_free, 0, cap); + } } #[test] From 572873fce0365cbba75557458ee5d7cb744bac12 Mon Sep 17 00:00:00 2001 From: the8472 Date: Sun, 4 Apr 2021 01:38:58 +0200 Subject: [PATCH 2/2] suggestion from review Co-authored-by: Ralf Jung --- library/alloc/tests/vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 026d3f63bb77a..cdd18520c599c 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1091,7 +1091,7 @@ fn test_from_iter_specialization_panic_during_drop_leaks() { assert_eq!(unsafe { DROP_COUNTER }, 1); // clean up the leak to keep miri happy unsafe { - Vec::from_raw_parts(to_free, 0, cap); + drop(Vec::from_raw_parts(to_free, 0, cap)); } }