Skip to content

Commit 62ce124

Browse files
authored
Auto merge of #209 - RalfJung:miri, r=mbrubeck
enable Miri leak checker Works around #208
2 parents 3957cd8 + cbe3620 commit 62ce124

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,8 @@ impl<A: Array> SmallVec<A> {
865865

866866
/// Insert multiple elements at position `index`, shifting all following elements toward the
867867
/// back.
868+
///
869+
/// Note: when the iterator panics, this can leak memory.
868870
pub fn insert_many<I: IntoIterator<Item = A::Item>>(&mut self, index: usize, iterable: I) {
869871
let iter = iterable.into_iter();
870872
if index == self.len() {
@@ -2092,19 +2094,27 @@ mod tests {
20922094
}
20932095
}
20942096

2097+
// These boxes are leaked on purpose by panicking `insert_many`,
2098+
// so we clean them up manually to appease Miri's leak checker.
2099+
let mut box1 = Box::new(false);
2100+
let mut box2 = Box::new(false);
2101+
20952102
let mut vec: SmallVec<[PanicOnDoubleDrop; 0]> = vec![
20962103
PanicOnDoubleDrop {
2097-
dropped: Box::new(false),
2104+
dropped: unsafe { Box::from_raw(&mut *box1) },
20982105
},
20992106
PanicOnDoubleDrop {
2100-
dropped: Box::new(false),
2107+
dropped: unsafe { Box::from_raw(&mut *box2) },
21012108
},
21022109
]
21032110
.into();
21042111
let result = ::std::panic::catch_unwind(move || {
21052112
vec.insert_many(0, BadIter);
21062113
});
21072114
assert!(result.is_err());
2115+
2116+
drop(box1);
2117+
drop(box2);
21082118
}
21092119

21102120
#[test]

scripts/run_miri.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ rustup default "$MIRI_NIGHTLY"
1616
rustup component add miri
1717
cargo miri setup
1818

19-
cargo miri test --verbose -- -Zmiri-ignore-leaks
20-
cargo miri test --verbose --features union -- -Zmiri-ignore-leaks
21-
cargo miri test --verbose --all-features -- -Zmiri-ignore-leaks
19+
cargo miri test --verbose
20+
cargo miri test --verbose --features union
21+
cargo miri test --verbose --all-features

0 commit comments

Comments
 (0)