diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2019-12-13 19:32:16 +0100 |
|---|---|---|
| committer | Jonas Schievink <jonasschievink@gmail.com> | 2020-01-19 20:24:08 +0100 |
| commit | b04ca13873d5ef5e5b18195aaf8925562302e8e0 (patch) | |
| tree | a6da6c16e2151a8f4c7e13a9d3386c8442912f11 /src/liballoc/tests | |
| parent | dc492452dae29d75b14afe3559f5fb59be7f2d3a (diff) | |
| download | rust-b04ca13873d5ef5e5b18195aaf8925562302e8e0.tar.gz rust-b04ca13873d5ef5e5b18195aaf8925562302e8e0.zip | |
Fix leak in VecDeque::drain when drop panics
Diffstat (limited to 'src/liballoc/tests')
| -rw-r--r-- | src/liballoc/tests/vec_deque.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index 2dc50d0c70e..07f1f098954 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -1606,3 +1606,41 @@ fn truncate_leak() { assert_eq!(unsafe { DROPS }, 7); } + +#[test] +fn test_drain_leak() { + static mut DROPS: i32 = 0; + + #[derive(Debug, PartialEq)] + struct D(u32, bool); + + impl Drop for D { + fn drop(&mut self) { + unsafe { + DROPS += 1; + } + + if self.1 { + panic!("panic in `drop`"); + } + } + } + + let mut v = VecDeque::new(); + v.push_back(D(4, false)); + v.push_back(D(5, false)); + v.push_back(D(6, false)); + v.push_front(D(3, false)); + v.push_front(D(2, true)); + v.push_front(D(1, false)); + v.push_front(D(0, false)); + + catch_unwind(AssertUnwindSafe(|| { + v.drain(1..=4); + })).ok(); + + assert_eq!(unsafe { DROPS }, 4); + assert_eq!(v.len(), 3); + drop(v); + assert_eq!(unsafe { DROPS }, 7); +} |
