std::io::stdin() leaking memory, says memcheck

84 points guildem

I was coding and testing my memory consumption, and I saw on memcheck that with the simplest possible code loading stdin(), some leaks appear. I'm almost sure this has a good explanation, and isn't a "real" leak. I read the documentation, made some research, but found nothing.

Does someone can explain to me, for learning purpose, why this code shows leaks ? Is this thread related ? Thanks !

// main.rs

fn main() {
    let _ = std::io::stdin();
}
$ cargo -V
cargo 1.60.0 (d1fd9fe 2022-03-01)
$ rustc -V
rustc 1.60.0 (7737e0b5c 2022-04-04)
$ cargo build --release; valgrind target/release/test
    Finished release [optimized] target(s) in 0.00s
==1008440== Memcheck, a memory error detector
==1008440== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1008440== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==1008440== Command: target/release/test
==1008440==
==1008440==
==1008440== HEAP SUMMARY:
==1008440==     in use at exit: 8,232 bytes in 2 blocks
==1008440==   total heap usage: 12 allocs, 10 frees, 10,389 bytes allocated
==1008440==
==1008440== LEAK SUMMARY:
==1008440==    definitely lost: 0 bytes in 0 blocks
==1008440==    indirectly lost: 0 bytes in 0 blocks
==1008440==      possibly lost: 0 bytes in 0 blocks
==1008440==    still reachable: 8,232 bytes in 2 blocks
==1008440==         suppressed: 0 bytes in 0 blocks
==1008440== Rerun with --leak-check=full to see details of leaked memory
==1008440==
==1008440== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)