OS X 10.10 Valgrind 3.11.0 Box allocation leaks?

I am running Rust 1.4.0 on OS X 10.10.5 and tried the sample code at http://rustbyexample.com/scope/raii.html. I built Valgrind 3.11.0 on OS X.

pastoraleman@macbook:~/projects/rust$ ../valgrind/bin/valgrind --leak-check=full --show-leak-kinds=all ./raii
==29556== Memcheck, a memory error detector
==29556== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==29556== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==29556== Command: ./raii
==29556== 
==29556== 
==29556== HEAP SUMMARY:
==29556==     in use at exit: 35,053 bytes in 426 blocks
==29556==   total heap usage: 507 allocs, 81 frees, 41,205 bytes allocated
==29556== 
==29556== 104 bytes in 1 blocks are still reachable in loss record 46 of 82
==29556==    at 0x100043EA1: malloc (vg_replace_malloc.c:303)
==29556==    by 0x10017BD9F: tlv_allocate_and_initialize_for_key (in /usr/lib/system/libdyld.dylib)
==29556==    by 0x10017C548: tlv_get_addr (in /usr/lib/system/libdyld.dylib)
==29556==    by 0x1000021C9: sys_common::thread_info::set::hbb3014f373adf259zUr (in ./raii)
==29556==    by 0x1000061DC: rt::lang_start::hf0f318bf9acb9103hUw (in ./raii)
==29556==    by 0x100000D99: main (in ./raii)
==29556== 
==29556== LEAK SUMMARY:
==29556==    definitely lost: 0 bytes in 0 blocks
==29556==    indirectly lost: 0 bytes in 0 blocks
==29556==      possibly lost: 0 bytes in 0 blocks
==29556==    still reachable: 104 bytes in 1 blocks
==29556==         suppressed: 34,949 bytes in 425 blocks
==29556== 
==29556== For counts of detected and suppressed errors, rerun with: -v
==29556== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 17)

The Valgrind FAQ says that the "still reachable" entries are probably OK, but from the raii example code I was expecting to see "All heap blocks were freed -- no leaks are possible". Am I doing something wrong, is this typical behaviour on OS X, or perhaps something else?

Many thanks.

I believe that this is caused by OSX's C runtime not destroying thread locals on the main thread at program termination.

1 Like

Thank you for the reply. I have done some more testing, and the behaviour appears consistent. I did:

fn main() {

    let mystr = "Boo!";

    let len = mystr.len();

    println!("String len: {}", len);

}

And still had some "still reachable" entries.

pastoraleman@macbook:~/projects/rust$ ../valgrind/bin/valgrind --leak-check=full --show-leak-kinds=all ./mystr
==30025== Memcheck, a memory error detector
==30025== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==30025== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==30025== Command: ./mystr
==30025== 
String len: 4
==30025== 
==30025== HEAP SUMMARY:
==30025==     in use at exit: 35,085 bytes in 426 blocks
==30025==   total heap usage: 509 allocs, 83 frees, 41,301 bytes allocated
==30025== 
==30025== 152 bytes in 1 blocks are still reachable in loss record 48 of 80
==30025==    at 0x100048EA1: malloc (vg_replace_malloc.c:303)
==30025==    by 0x100180D9F: tlv_allocate_and_initialize_for_key (in /usr/lib/system/libdyld.dylib)
==30025==    by 0x100181548: tlv_get_addr (in /usr/lib/system/libdyld.dylib)
==30025==    by 0x1000047C9: sys_common::thread_info::set::hbb3014f373adf259zUr (in ./mystr)
==30025==    by 0x10000883C: rt::lang_start::hf0f318bf9acb9103hUw (in ./mystr)
==30025==    by 0x100001459: main (in ./mystr)
==30025== 
==30025== LEAK SUMMARY:
==30025==    definitely lost: 0 bytes in 0 blocks
==30025==    indirectly lost: 0 bytes in 0 blocks
==30025==      possibly lost: 0 bytes in 0 blocks
==30025==    still reachable: 152 bytes in 1 blocks
==30025==         suppressed: 34,933 bytes in 425 blocks
==30025== 
==30025== For counts of detected and suppressed errors, rerun with: -v
==30025== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 15)

I will ignore any further hits against this counter on OS X.