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

Vec backing buffer leaks on panic during into_iter #69770

Closed
RalfJung opened this issue Mar 6, 2020 · 0 comments · Fixed by #69828
Closed

Vec backing buffer leaks on panic during into_iter #69770

RalfJung opened this issue Mar 6, 2020 · 0 comments · Fixed by #69828
Labels
A-collections Area: `std::collection` C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Mar 6, 2020

When running the test_into_iter_leak test in Miri, it complains about a memory leak:

note: created allocation with id 228443
   --> /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/alloc.rs:81:47
    |
81  |     __rust_alloc(layout.size(), layout.align())
    |                                               ^ created allocation with id 228443
    |
    = note: inside call to `std::alloc::alloc` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/alloc.rs:169:22
    = note: inside call to `<std::alloc::Global as std::alloc::AllocRef>::alloc` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/alloc.rs:203:15
note: inside call to `alloc::alloc::exchange_malloc` at <::alloc::macros::vec macros>:2:46
   --> alloc_miri_test/../liballoc/tests/vec.rs:786:13
    |
786 |     let v = vec![D(false), D(true), D(false)];
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `vec::test_into_iter_leak` at alloc_miri_test/../liballoc/tests/vec.rs:769:1
   --> alloc_miri_test/../liballoc/tests/vec.rs:769:1
    |
769 | / fn test_into_iter_leak() {
770 | |     static mut DROPS: i32 = 0;
771 | |
772 | |     struct D(bool);
...   |
790 | |     assert_eq!(unsafe { DROPS }, 3);
791 | | }
    | |_^

### LEAK REPORT ###
Alloc 228443: 00 01 00 (3 bytes, alignment 1) (Rust)

Given that the leaked allocation contains "00 01 00", that seems a lot like the backing store of a Vec with initial content D(false), D(true), D(false).

@RalfJung RalfJung added A-collections Area: `std::collection` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 6, 2020
@bors bors closed this as completed in 080d413 Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collection` C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant