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

Miri reports leaks #1062

Closed
emilio opened this issue Jun 25, 2023 · 3 comments
Closed

Miri reports leaks #1062

emilio opened this issue Jun 25, 2023 · 3 comments

Comments

@emilio
Copy link
Contributor

emilio commented Jun 25, 2023

I think this might be a miri false positive. I was writing some tests for use_current_thread (#1052), and I thought they were my fault but they also repro in other tests.

$ cargo miri test --test scoped_threadpool
[...]
error: memory leaked: alloc137749 (Rust heap, size: 152, align: 8), allocated here:                                                                                                                                                         
   --> /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:102:9                                                                                                               
    |                                                                                                                                                                                                                                       
102 |         __rust_alloc(layout.size(), layout.align())                                                                                                                                                                                   
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                   
    |                                                                                                                                                                                                                                       
    = note: inside `std::alloc::alloc` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:102:9: 102:52                                                                    
    = note: inside `std::alloc::Global::alloc_impl` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:185:73: 185:86                                                      
    = note: inside `<std::alloc::Global as std::alloc::Allocator>::allocate` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:245:9: 245:39                              
    = note: inside `alloc::alloc::exchange_malloc` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:334:11: 334:34
    = note: inside `std::boxed::Box::<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>::new` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:21
7:9: 217:20
    = note: inside `<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag> as crossbeam_epoch::atomic::Pointable>::init` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/
atomic.rs:200:23: 200:37
    = note: inside `crossbeam_epoch::atomic::Owned::<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>::init` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/atomic
.rs:1159:35: 1159:48
    = note: inside `crossbeam_epoch::atomic::Owned::<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>::new` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/atomic.
rs:1144:9: 1144:25
    = note: inside `crossbeam_epoch::sync::queue::Queue::<crossbeam_epoch::internal::SealedBag>::push` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/sync/queue.rs:99:19: 102:11
    = note: inside `crossbeam_epoch::internal::Global::push_bag` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/internal.rs:190:9: 190:48
    = note: inside `crossbeam_epoch::internal::Local::finalize` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/internal.rs:515:13: 516:65
    = note: inside `crossbeam_epoch::internal::Local::release_handle` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/internal.rs:498:13: 498:28
    = note: inside `<crossbeam_epoch::collector::LocalHandle as std::ops::Drop>::drop` at /home/emilio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.14/src/collector.rs:101:13: 101:48
    = note: inside `std::ptr::drop_in_place::<crossbeam_epoch::collector::LocalHandle> - shim(Some(crossbeam_epoch::collector::LocalHandle))` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/libra
ry/core/src/ptr/mod.rs:497:1: 497:56
    = note: inside `std::ptr::drop_in_place::<std::option::Option<crossbeam_epoch::collector::LocalHandle>> - shim(Some(std::option::Option<crossbeam_epoch::collector::LocalHandle>))` at /home/emilio/.rustup/toolchains/nightly-x86_64-un
known-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:497:1: 497:56
    = note: inside `std::mem::drop::<std::option::Option<crossbeam_epoch::collector::LocalHandle>>` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:987:24: 987:25
    = note: inside closure at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/common/thread_local/fast_local.rs:243:9: 243:20
    = note: inside `<[closure@std::sys::common::thread_local::fast_local::destroy_value<crossbeam_epoch::collector::LocalHandle>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim` at /home/emilio/.rustup/toolchains/nightly-x86_64
-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: 250:71
    = note: inside `<std::panic::AssertUnwindSafe<[closure@std::sys::common::thread_local::fast_local::destroy_value<crossbeam_epoch::collector::LocalHandle>::{closure#0}]> as std::ops::FnOnce<()>>::call_once` at /home/emilio/.rustup/to
olchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9: 271:19
    = note: inside `std::panicking::r#try::do_call::<std::panic::AssertUnwindSafe<[closure@std::sys::common::thread_local::fast_local::destroy_value<crossbeam_epoch::collector::LocalHandle>::{closure#0}]>, ()>` at /home/emilio/.rustup/t
oolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:500:40: 500:43
    = note: inside `std::panicking::r#try::<(), std::panic::AssertUnwindSafe<[closure@std::sys::common::thread_local::fast_local::destroy_value<crossbeam_epoch::collector::LocalHandle>::{closure#0}]>>` at /home/emilio/.rustup/toolchains
/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:464:19: 464:81
    = note: inside `std::panic::catch_unwind::<std::panic::AssertUnwindSafe<[closure@std::sys::common::thread_local::fast_local::destroy_value<crossbeam_epoch::collector::LocalHandle>::{closure#0}]>, ()>` at /home/emilio/.rustup/toolcha
ins/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:142:14: 142:33
    = note: inside `std::sys::common::thread_local::fast_local::destroy_value::<crossbeam_epoch::collector::LocalHandle>` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/commo
n/thread_local/fast_local.rs:240:21: 244:8
    = note: inside `std::sys_common::thread_local_dtor::register_dtor_fallback::run_dtors` at /home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/thread_local_dtor.rs:43:17: 4
3:26
[...]

And so on.

@emilio
Copy link
Contributor Author

emilio commented Jun 25, 2023

Valgrind doesn't report the same:

$ valgrind /home/emilio/src/moz/rayon/target/debug/deps/scoped_threadpool-42ac87d907424fc2                                                                                                                                               
==48462== Memcheck, a memory error detector
==48462== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==48462== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==48462== Command: /home/emilio/src/moz/rayon/target/debug/deps/scoped_threadpool-42ac87d907424fc2
==48462== 

running 3 tests
test missing_scoped_tls ... ok
test build_scoped_tls_threadpool ... ok
test spawn_scoped_tls_threadpool ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.85s

==48462== 
==48462== HEAP SUMMARY:
==48462==     in use at exit: 186,440 bytes in 91 blocks
==48462==   total heap usage: 2,060 allocs, 1,969 frees, 693,322 bytes allocated
==48462== 
==48462== LEAK SUMMARY:
==48462==    definitely lost: 0 bytes in 0 blocks
==48462==    indirectly lost: 0 bytes in 0 blocks
==48462==      possibly lost: 84,160 bytes in 40 blocks
==48462==    still reachable: 102,280 bytes in 51 blocks
==48462==         suppressed: 0 bytes in 0 blocks
==48462== Rerun with --leak-check=full to see details of leaked memory
==48462== 
==48462== For lists of detected and suppressed errors, rerun with: -s
==48462== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

So maybe a miri false-positive?

@emilio
Copy link
Contributor Author

emilio commented Jun 25, 2023

==48961== 39,976 bytes in 19 blocks are possibly lost in loss record 4 of 6
==48961==    at 0x4841848: malloc (vg_replace_malloc.c:431)
==48961==    by 0x1DC7CC: alloc (alloc.rs:102)
==48961==    by 0x1DC7CC: alloc::alloc::Global::alloc_impl (alloc.rs:185)
==48961==    by 0x1DC566: allocate (alloc.rs:245)
==48961==    by 0x1DC566: alloc::alloc::exchange_malloc (alloc.rs:334)
==48961==    by 0x1DCAF7: new<crossbeam_epoch::internal::Local> (boxed.rs:217)
==48961==    by 0x1DCAF7: <T as crossbeam_epoch::atomic::Pointable>::init (atomic.rs:200)
==48961==    by 0x1E3D36: crossbeam_epoch::atomic::Owned<T>::init (atomic.rs:1159)
==48961==    by 0x1E3D06: crossbeam_epoch::atomic::Owned<T>::new (atomic.rs:1144)
==48961==    by 0x1DE284: crossbeam_epoch::internal::Local::register (internal.rs:321)
==48961==    by 0x1DCC99: crossbeam_epoch::collector::Collector::register (collector.rs:45)
==48961==    by 0x1E018F: crossbeam_epoch::default::HANDLE::__init (default.rs:34)
==48961==    by 0x1E01EB: crossbeam_epoch::default::HANDLE::__getit::{{closure}} (fast_local.rs:103)
==48961==    by 0x1DBB75: std::sys::common::thread_local::lazy::LazyKeyInner<T>::initialize (mod.rs:54)
==48961==    by 0x1DB733: std::sys::common::thread_local::fast_local::Key<T>::try_initialize (fast_local.rs:194)

It seems miri doesn't consider TLS-stored memory as reachable? If you agree with this diagnosis we can probably close this.

@emilio
Copy link
Contributor Author

emilio commented Jun 25, 2023

I guess this is rust-lang/miri#2881

@emilio emilio closed this as completed Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant