Skip to content

Panicking insert_many leaks memory #208

Closed
@RalfJung

Description

@RalfJung

The test_insert_many_panic test leaks memory. Both of these allocations here to do get freed, presumably due to the panicking insert_many:

rust-smallvec/lib.rs

Lines 2096 to 2101 in 3957cd8

PanicOnDoubleDrop {
dropped: Box::new(false),
},
PanicOnDoubleDrop {
dropped: Box::new(false),
},

Found by Miri:

note: tracking was triggered
    --> /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/alloc.rs:80:47
     |
80   |     __rust_alloc(layout.size(), layout.align())
     |                                               ^ created allocation with id 129830
     |
     = note: inside `alloc::alloc::alloc` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/alloc.rs:80:47
     = note: inside `<alloc::alloc::Global as core::alloc::AllocRef>::alloc` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/alloc.rs:174:49
     = note: inside `alloc::alloc::exchange_malloc` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/alloc.rs:268:11
     = note: inside `alloc::boxed::Box::<bool>::new` at /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/liballoc/boxed.rs:174:9
note: inside `tests::test_insert_many_panic` at lib.rs:2100:26
    --> lib.rs:2100:26
     |
2100 |                 dropped: Box::new(false),
     |                          ^^^^^^^^^^^^^^^
note: inside closure at lib.rs:2072:5
    --> lib.rs:2072:5
     |
2072 | /     fn test_insert_many_panic() {
2073 | |         struct PanicOnDoubleDrop {
2074 | |             dropped: Box<bool>,
2075 | |         }
...    |
2107 | |         assert!(result.is_err());
2108 | |     }
     | |_____^

The following memory was leaked:
alloc129816 (Rust heap, size: 1, align: 1) {
    00                                              │ .
}
alloc129830 (Rust heap, size: 1, align: 1) {
    00                                              │ .
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions