diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-08 11:51:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-08 11:51:17 +0100 |
| commit | f497325b13fea12b5771b0f123880847598dd9d1 (patch) | |
| tree | 432dc13538a752e1674ca2b6581b0f4c9fe18f47 /src/liballoc/tests | |
| parent | 5adfa4bd482d23c52d95e11d8b31926bad100fce (diff) | |
| parent | 44c97c43b5d3df5d76381f80fb8ad0042c6ccf55 (diff) | |
Rollup merge of #69776 - ssomers:fix69769, r=Mark-Simulacrum
Fix & test leak of some BTreeMap nodes on panic during `into_iter` Fixes #69769
Diffstat (limited to 'src/liballoc/tests')
| -rw-r--r-- | src/liballoc/tests/btree/map.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/liballoc/tests/btree/map.rs b/src/liballoc/tests/btree/map.rs index fd07a4d3926..d05eec19346 100644 --- a/src/liballoc/tests/btree/map.rs +++ b/src/liballoc/tests/btree/map.rs @@ -1021,7 +1021,7 @@ fn test_split_off_large_random_sorted() { } #[test] -fn test_into_iter_drop_leak() { +fn test_into_iter_drop_leak_1() { static DROPS: AtomicU32 = AtomicU32::new(0); struct D; @@ -1045,3 +1045,27 @@ fn test_into_iter_drop_leak() { assert_eq!(DROPS.load(Ordering::SeqCst), 5); } + +#[test] +fn test_into_iter_drop_leak_2() { + let size = 12; // to obtain tree with 2 levels (having edges to leaf nodes) + static DROPS: AtomicU32 = AtomicU32::new(0); + static PANIC_POINT: AtomicU32 = AtomicU32::new(0); + + struct D; + impl Drop for D { + fn drop(&mut self) { + if DROPS.fetch_add(1, Ordering::SeqCst) == PANIC_POINT.load(Ordering::SeqCst) { + panic!("panic in `drop`"); + } + } + } + + for panic_point in vec![0, 1, size - 2, size - 1] { + DROPS.store(0, Ordering::SeqCst); + PANIC_POINT.store(panic_point, Ordering::SeqCst); + let map: BTreeMap<_, _> = (0..size).map(|i| (i, D)).collect(); + catch_unwind(move || drop(map.into_iter())).ok(); + assert_eq!(DROPS.load(Ordering::SeqCst), size); + } +} |
