Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Drop items getting leaked in Filter::next_chunk #126879

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
regression test for leaks in the the Filter::next_chunk implementation
previously next_chunk would forget items rejected by the filter
  • Loading branch information
the8472 committed Jun 25, 2024
commit 0d7aef9738b25ed4f84d11deb0add8d5345613b0
13 changes: 13 additions & 0 deletions library/core/tests/iter/adapters/filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::iter::*;
use std::rc::Rc;

#[test]
fn test_iterator_filter_count() {
Expand Down Expand Up @@ -50,3 +51,15 @@ fn test_double_ended_filter() {
assert_eq!(it.next().unwrap(), &2);
assert_eq!(it.next_back(), None);
}

#[test]
fn test_next_chunk_does_not_leak() {
let drop_witness: [_; 5] = std::array::from_fn(|_| Rc::new(()));

let v = (0..5).map(|i| drop_witness[i].clone()).collect::<Vec<_>>();
let _ = v.into_iter().filter(|_| false).next_chunk::<1>();

for ref w in drop_witness {
assert_eq!(Rc::strong_count(w), 1);
}
}
Loading