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 leak in thread local allocation #123961

Closed
Mark-Simulacrum opened this issue Apr 15, 2024 · 4 comments
Closed

Miri reports leak in thread local allocation #123961

Mark-Simulacrum opened this issue Apr 15, 2024 · 4 comments
Labels
A-thread-locals Area: Thread local storage (TLS) I-memleak Issue: Runtime memory leak without `mem::forget`. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@Mark-Simulacrum
Copy link
Member

This failed in #123941 (I'm hoping it's not related to that PR's changes) on gnu-aux:

2024-04-15T05:56:37.4909233Z �[1m�[32m     Running�[0m unittests src/lib.rs (obj/build/x86_64-unknown-linux-gnu/stage1-std/miri/i686-pc-windows-gnu/debug/deps/std-8c5441287b78bd95.exe)
[...]
2024-04-15T06:03:09.6754201Z error: memory leaked: alloc3166557 (Rust heap, size: 16, align: 4), allocated here:
2024-04-15T06:03:09.6760527Z ##[error]   --> /checkout/library/alloc/src/alloc.rs:100:9
2024-04-15T06:03:09.6762309Z     |
2024-04-15T06:03:09.6764983Z 100 |         __rust_alloc(layout.size(), layout.align())
2024-04-15T06:03:09.6765800Z     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-15T06:03:09.6766357Z     |
2024-04-15T06:03:09.6766612Z     = note: BACKTRACE:
2024-04-15T06:03:09.6767207Z     = note: inside `realstd::alloc::alloc` at /checkout/library/alloc/src/alloc.rs:100:9: 100:52
2024-04-15T06:03:09.6768136Z     = note: inside `realstd::alloc::Global::alloc_impl` at /checkout/library/alloc/src/alloc.rs:183:73: 183:86
2024-04-15T06:03:09.6769447Z     = note: inside `<realstd::alloc::Global as core::alloc::Allocator>::allocate` at /checkout/library/alloc/src/alloc.rs:243:9: 243:39
2024-04-15T06:03:09.6770476Z     = note: inside `alloc_crate::alloc::exchange_malloc` at /checkout/library/alloc/src/alloc.rs:332:11: 332:34
2024-04-15T06:03:09.6771753Z     = note: inside `realstd::boxed::Box::<realstd::sys::thread_local::os_local::Value<core::cell::Cell<(usize, bool)>>>::new` at /checkout/library/alloc/src/boxed.rs:218:9: 218:20
2024-04-15T06:03:09.6773482Z     = note: inside `realstd::thread::local_impl::Key::<core::cell::Cell<(usize, bool)>>::try_initialize::<{closure@realstd::rt::panic_count::LOCAL_PANIC_COUNT::__getit::{closure#0}}>` at /checkout/library/std/src/sys/thread_local/os_local.rs:145:37: 145:94
2024-04-15T06:03:09.6775495Z     = note: inside `realstd::thread::local_impl::Key::<core::cell::Cell<(usize, bool)>>::get::<{closure@realstd::rt::panic_count::LOCAL_PANIC_COUNT::__getit::{closure#0}}>` at /checkout/library/std/src/sys/thread_local/os_local.rs:127:18: 127:43
2024-04-15T06:03:09.6777050Z     = note: inside `realstd::rt::panic_count::LOCAL_PANIC_COUNT::__getit` at /checkout/library/std/src/sys/thread_local/os_local.rs:28:17: 37:19
2024-04-15T06:03:09.6778549Z     = note: inside `realstd::thread::LocalKey::<core::cell::Cell<(usize, bool)>>::try_with::<{closure@realstd::rt::panic_count::is_zero_slow_path::{closure#0}}, bool>` at /checkout/library/std/src/thread/local.rs:285:37: 285:55
2024-04-15T06:03:09.6780283Z     = note: inside `realstd::thread::LocalKey::<core::cell::Cell<(usize, bool)>>::with::<{closure@realstd::rt::panic_count::is_zero_slow_path::{closure#0}}, bool>` at /checkout/library/std/src/thread/local.rs:262:9: 262:25
2024-04-15T06:03:09.6781634Z     = note: inside `realstd::rt::panic_count::is_zero_slow_path` at /checkout/library/std/src/panicking.rs:457:9: 457:51
2024-04-15T06:03:09.6782624Z     = note: inside `realstd::rt::panic_count::count_is_zero` at /checkout/library/std/src/panicking.rs:448:13: 448:32
2024-04-15T06:03:09.6783568Z     = note: inside `realstd::panicking::panicking` at /checkout/library/std/src/panicking.rs:587:6: 587:34
2024-04-15T06:03:09.6784553Z     = note: inside `realstd::thread::panicking` at /checkout/library/std/src/thread/mod.rs:830:5: 830:27
2024-04-15T06:03:09.6785529Z     = note: inside `realstd::sync::poison::Flag::guard` at /checkout/library/std/src/sync/poison.rs:45:24: 45:43
2024-04-15T06:03:09.6786817Z     = note: inside `realstd::sync::MutexGuard::<'_, realstd::sync::mpmc::waker::Waker>::new` at /checkout/library/std/src/sync/mutex.rs:525:28: 525:47
2024-04-15T06:03:09.6788017Z     = note: inside `realstd::sync::Mutex::<realstd::sync::mpmc::waker::Waker>::lock` at /checkout/library/std/src/sync/mutex.rs:318:13: 318:34
2024-04-15T06:03:09.6789155Z     = note: inside `realstd::sync::mpmc::waker::SyncWaker::notify` at /checkout/library/std/src/sync/mpmc/waker.rs:174:29: 174:46
2024-04-15T06:03:09.6790635Z     = note: inside `realstd::sync::mpmc::list::Channel::<test::event::CompletedTest>::write` at /checkout/library/std/src/sync/mpmc/list.rs:273:9: 273:32
2024-04-15T06:03:09.6791880Z     = note: inside `realstd::sync::mpmc::list::Channel::<test::event::CompletedTest>::send` at /checkout/library/std/src/sync/mpmc/list.rs:403:18: 403:40
2024-04-15T06:03:09.6793099Z     = note: inside `realstd::sync::mpmc::Sender::<test::event::CompletedTest>::send` at /checkout/library/std/src/sync/mpmc/mod.rs:128:41: 128:61
2024-04-15T06:03:09.6794290Z     = note: inside `realstd::sync::mpsc::Sender::<test::event::CompletedTest>::send` at /checkout/library/std/src/sync/mpsc/mod.rs:613:9: 613:27
2024-04-15T06:03:09.6795291Z     = note: inside `test::run_test_in_process` at /checkout/library/test/src/lib.rs:661:5: 661:29
2024-04-15T06:03:09.6796040Z     = note: inside closure at /checkout/library/test/src/lib.rs:570:43: 578:18
2024-04-15T06:03:09.6796709Z     = note: inside closure at /checkout/library/test/src/lib.rs:598:41: 598:83
2024-04-15T06:03:09.6797917Z     = note: inside `realstd::sys_common::backtrace::__rust_begin_short_backtrace::<{closure@test::run_test::{closure#1}}, ()>` at /checkout/library/std/src/sys_common/backtrace.rs:155:18: 155:21
2024-04-15T06:03:09.6799058Z     = note: inside closure at /checkout/library/std/src/thread/mod.rs:542:17: 542:78
2024-04-15T06:03:09.6800731Z     = note: inside `<core::panic::AssertUnwindSafe<{closure@realstd::thread::Builder::spawn_unchecked_<'_, '_, {closure@test::run_test::{closure#1}}, ()>::{closure#2}::{closure#0}}> as core::ops::FnOnce<()>>::call_once` at /checkout/library/core/src/panic/unwind_safe.rs:272:9: 272:19
2024-04-15T06:03:09.6803054Z     = note: inside `realstd::panicking::r#try::do_call::<core::panic::AssertUnwindSafe<{closure@realstd::thread::Builder::spawn_unchecked_<'_, '_, {closure@test::run_test::{closure#1}}, ()>::{closure#2}::{closure#0}}>, ()>` at /checkout/library/std/src/panicking.rs:552:40: 552:43
2024-04-15T06:03:09.6805259Z     = note: inside `realstd::panicking::r#try::<(), core::panic::AssertUnwindSafe<{closure@realstd::thread::Builder::spawn_unchecked_<'_, '_, {closure@test::run_test::{closure#1}}, ()>::{closure#2}::{closure#0}}>>` at /checkout/library/std/src/panicking.rs:516:19: 516:88
2024-04-15T06:03:09.6807415Z     = note: inside `realstd::panic::catch_unwind::<core::panic::AssertUnwindSafe<{closure@realstd::thread::Builder::spawn_unchecked_<'_, '_, {closure@test::run_test::{closure#1}}, ()>::{closure#2}::{closure#0}}>, ()>` at /checkout/library/std/src/panic.rs:149:14: 149:33
2024-04-15T06:03:09.6808783Z     = note: inside closure at /checkout/library/std/src/thread/mod.rs:541:30: 543:16
2024-04-15T06:03:09.6810256Z     = note: inside `<{closure@realstd::thread::Builder::spawn_unchecked_<'_, '_, {closure@test::run_test::{closure#1}}, ()>::{closure#2}} as core::ops::FnOnce<()>>::call_once - shim(vtable)` at /checkout/library/core/src/ops/function.rs:250:5: 250:71
2024-04-15T06:03:09.6811816Z     = note: inside `<realstd::boxed::Box<dyn core::ops::FnOnce()> as core::ops::FnOnce<()>>::call_once` at /checkout/library/alloc/src/boxed.rs:2018:9: 2018:52
2024-04-15T06:03:09.6813179Z     = note: inside `<realstd::boxed::Box<realstd::boxed::Box<dyn core::ops::FnOnce()>> as core::ops::FnOnce<()>>::call_once` at /checkout/library/alloc/src/boxed.rs:2018:9: 2018:52
2024-04-15T06:03:09.6814546Z     = note: inside `realstd::sys::pal::windows::thread::Thread::new::thread_start` at /checkout/library/std/src/sys/pal/windows/thread.rs:52:13: 52:60
2024-04-15T06:03:09.6815241Z 
2024-04-15T06:03:09.6815699Z note: the evaluated program leaked memory, pass `-Zmiri-ignore-leaks` to disable this check
@Mark-Simulacrum Mark-Simulacrum added T-libs Relevant to the library team, which will review and decide on the PR/issue. I-memleak Issue: Runtime memory leak without `mem::forget`. labels Apr 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 15, 2024
@bjorn3
Copy link
Member

bjorn3 commented Apr 15, 2024

cc @rust-lang/miri

@jieyouxu jieyouxu added A-thread-locals Area: Thread local storage (TLS) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2024
@saethlin
Copy link
Member

I suspect this is another duplicate report of #123583, though it has a slightly different backtrace. See #123937

@Mark-Simulacrum
Copy link
Member Author

Ah, yes, that seems plausible. I ignored that issue since it mentions reentrant locks and this backtrace at least doesn't seem like it involves those (maybe I missed it).

@RalfJung
Copy link
Member

Yeah the issue would affect all thread-local storage. So seems plausible that it is the same issue. So hopefully this is fixed by #123937.

Closing as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-thread-locals Area: Thread local storage (TLS) I-memleak Issue: Runtime memory leak without `mem::forget`. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants