You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cargo install cargo-valgrind
$ cargo new valgrind-fails
add blank test in src/main.rs:fnmain(){println!("Hello, world!");}#[cfg(test)]mod tests {#[test]pubfnhmm(){}}
$ cargo +nightly valgrind test -r
Current output
Error leaked 48 B in 1 block
Info stack trace (user code at the bottom)
at malloc
at std::thread::Thread::new
at std::thread::current::init_current
at std::sync::mpmc::context::Context::new
at std::sys::thread_local::native::lazy::Storage<T,D>::initialize
at std::sync::mpmc::list::Channel<T>::recv
at test::console::run_tests_console
at test::test_main
at test::test_main_static
at std::sys::backtrace::__rust_begin_short_backtrace
at std::rt::lang_start::{{closure}}
at std::rt::lang_start_internal
Summary Leaked 48 B total (0 other errors)
error: test failed, to rerun pass `--bin valgrind-fails`
On another machine, nightly works fine but stable sporadically fails in debug mode:
$ cargo valgrind test
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.03s
Running unittests src/main.rs (target/debug/deps/vaaa-a01420ed07e277c8)
running 1 test
test tests::hmm ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s
Error leaked 56 B in 1 block
Info stack trace (user code at the bottom)
at malloc (vg_replace_malloc.c:446)
at alloc (alloc.rs:99)
at alloc_impl (alloc.rs:192)
at allocate (alloc.rs:254)
at {closure#0}<std::thread::Inner> (sync.rs:483)
at allocate_for_layout<core::mem::maybe_uninit::MaybeUninit<std::thread::Inner>, alloc::sync::{impl#14}::new_uninit::{closure_env#0}<std::thread::Inner>, fn(*mut u8) -> *mut alloc::sync::ArcInner<core::mem::maybe_uninit::MaybeUninit<std::thread::Inner>>> (sync.rs:1925)
at new_uninit<std::thread::Inner> (sync.rs:481)
at new_inner (mod.rs:1343)
at new_main (mod.rs:1333)
at init (rt.rs:113)
at {closure#0} (rt.rs:172)
at do_call<std::rt::lang_start_internal::{closure_env#0}, ()> (panicking.rs:557)
at try<(), std::rt::lang_start_internal::{closure_env#0}> (panicking.rs:520)
at catch_unwind<std::rt::lang_start_internal::{closure_env#0}, ()> (panic.rs:358)
at std::rt::lang_start_internal (rt.rs:172)
at std::rt::lang_start (rt.rs:194)
at main
Summary Leaked 56 B total (0 other errors)
error: test failed, to rerun pass `--bin vaaa`
Caused by:
process didn't exit successfully: `/home/matrix/.cargo/bin/cargo-valgrind /home/matrix/Documents/vaaa/target/debug/deps/vaaa-a01420ed07e277c8` (exit status: 127)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
If it is, the proposed solution is not really satisfying to me — not being able to rely on valgrinds return code for proper test CI is quite bothering.
If it is, the proposed solution is not really satisfying to me — not being able to rely on valgrinds return code for proper test CI is quite bothering.
You can use --errors-for-leak-kinds=definite to stop it being a bother.
The proposed solution seems to be "wait for #134085 to be merged". Personally, I'm fine with that. I pinned my valgrind CI to beta for now due to this.
You can use --errors-for-leak-kinds=definite to stop it being a bother.
Sure, that sort of works. But it does modify the behavior of valgrind, I'm telling it not to report to me everything it sees as it did before the regression, so that I can hide the fact that Rust itself leaks memory when it decides to (and not deterministically).
This will work as a patch, but it doesn't feel very pleasing, philosophically speaking. I do want to see every leak, but I also would like an empty cargo project to work on valgrind without tweaks.
But again, this is bleeding edge, I can live with it.
Activity
MRandl commentedon Jan 17, 2025
On another machine, nightly works fine but stable sporadically fails in debug mode:
rustc 1.83.0 (90b35a6 2024-11-26)
binary: rustc
commit-hash: 90b35a6
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1
[-]Nightly tests leak 48B systematically[/-][+]Tests sometimes leak around 50 bytes[/+]purplesyringa commentedon Jan 17, 2025
I think this is basically the same issue as #135608. I submitted my issue after minimizing precisely your reproducer.
MRandl commentedon Jan 17, 2025
If it is, the proposed solution is not really satisfying to me — not being able to rely on valgrinds return code for proper test CI is quite bothering.
ChrisDenton commentedon Jan 17, 2025
You can use
--errors-for-leak-kinds=definiteto stop it being a bother.purplesyringa commentedon Jan 17, 2025
The proposed solution seems to be "wait for #134085 to be merged". Personally, I'm fine with that. I pinned my valgrind CI to beta for now due to this.
MRandl commentedon Jan 17, 2025
Sure, that sort of works. But it does modify the behavior of valgrind, I'm telling it not to report to me everything it sees as it did before the regression, so that I can hide the fact that Rust itself leaks memory when it decides to (and not deterministically).
This will work as a patch, but it doesn't feel very pleasing, philosophically speaking. I do want to see every leak, but I also would like an empty cargo project to work on valgrind without tweaks.
But again, this is bleeding edge, I can live with it.
MRandl commentedon Jan 17, 2025
Fine by me!
MRandl commentedon Jan 17, 2025
Closing as duplicate
suppression for thread_local::native::lazy::Storage<>::get_or_init_sl…
ci: suppress rust std lib memory leak
ci: suppress rust std lib memory leak