rust-lang / rust

Empowering everyone to build reliable and efficient software.

Home Page:https://www.rust-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BTreeMap root node leaks on panic during `into_iter`

RalfJung opened this issue · comments

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

note: created allocation with id 143756
    --> /home/r/src/rust/rustc/src/liballoc/alloc.rs:81:47
     |
81   |     __rust_alloc(layout.size(), layout.align())
     |                                               ^ created allocation with id 143756
     |
     = note: inside call to `std::alloc::alloc` at /home/r/src/rust/rustc/src/liballoc/alloc.rs:169:22
     = note: inside call to `<std::alloc::Global as std::alloc::AllocRef>::alloc` at /home/r/src/rust/rustc/src/liballoc/alloc.rs:203:15
     = note: inside call to `alloc::alloc::exchange_malloc` at /home/r/src/rust/rustc/src/liballoc/boxed.rs:175:9
     = note: inside call to `std::boxed::Box::<alloc::collections::btree::node::LeafNode<&str, btree::map::test_into_iter_drop_leak::D>>::new` at /home/r/src/rust/rustc/src/liballoc/collections/btree/node.rs:211:43
     = note: inside call to `alloc::collections::btree::node::Root::<&str, btree::map::test_into_iter_drop_leak::D>::new_leaf` at /home/r/src/rust/rustc/src/liballoc/collections/btree/map.rs:1333:25
     = note: inside call to `std::collections::BTreeMap::<&str, btree::map::test_into_iter_drop_leak::D>::ensure_root_is_owned` at /home/r/src/rust/rustc/src/liballoc/collections/btree/map.rs:1067:9
     = note: inside call to `std::collections::BTreeMap::<&str, btree::map::test_into_iter_drop_leak::D>::entry` at /home/r/src/rust/rustc/src/liballoc/collections/btree/map.rs:838:15
note: inside call to `std::collections::BTreeMap::<&str, btree::map::test_into_iter_drop_leak::D>::insert` at alloc_miri_test/../liballoc/tests/btree/map.rs:1038:5
    --> alloc_miri_test/../liballoc/tests/btree/map.rs:1038:5
     |
1038 |     map.insert("a", D);
     |     ^^^^^^^^^^^^^^^^^^

### LEAK REPORT ###
Alloc 143756: 00 00 00 00 00 00 00 00 __ __ 05 00 __ __ __ __ 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ (192 bytes, alignment 8) (Rust)
                                                              └──────(143732)───────┘                         └──────(143850)───────┘                         └──────(143963)───────┘                         └──────(144092)───────┘                         └──────(144237)───────┘ 
Alloc 143732: 61 (1 bytes, alignment 1) (Static)
Alloc 143850: 62 (1 bytes, alignment 1) (Static)
Alloc 143963: 63 (1 bytes, alignment 1) (Static)
Alloc 144092: 64 (1 bytes, alignment 1) (Static)
Alloc 144237: 65 (1 bytes, alignment 1) (Static)

The leaked allocation is the root node of the map.

Also see this discussion where the issue came up.

Cc @ssomers