o Use the latest OpenBSD/amd64 and devel/valgrind (valgrind-3.10.1p5). o Dynamically link your target program. o Valgrind overrides some functions (alloc, free, string, memory) in libc using $LD_PRELOAD. o Embed symbols (cc -g). o Otherwise Valgrind reports problems using symbols.
This is a log when I run valgrind with top and immediately quit: --------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8< % valgrind --leak-check=full ./usr.bin/top/top ==25119== Memcheck, a memory error detector ==25119== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==25119== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==25119== Command: ./usr.bin/top/top ==25119== ==25119== Conditional jump or move depends on uninitialised value(s) ==25119== at 0x10F167: rundisplay (top.c:615) ==25119== by 0x110594: main (top.c:541) ==25119== ==25119== ==25119== FILE DESCRIPTORS: 3 open at exit. ==25119== Open file descriptor 2: ==25119== <inherited from parent> ==25119== ==25119== Open file descriptor 1: ==25119== <inherited from parent> ==25119== ==25119== Open file descriptor 0: ==25119== <inherited from parent> ==25119== ==25119== ==25119== HEAP SUMMARY: ==25119== in use at exit: 689,696 bytes in 203 blocks ==25119== total heap usage: 351 allocs, 148 frees, 986,877 bytes allocated ==25119== ==25119== 1,024 bytes in 1 blocks are definitely lost in loss record 44 of 59 ==25119== at 0x501A1F0: calloc (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-openbsd.so) ==25119== by 0x544831F: _nc_copy_entry (alloc_entry.c:109) ==25119== by 0x5442889: enqueue (comp_parse.c:71) ==25119== by 0x5442889: _nc_read_entry_source (comp_parse.c:154) ==25119== by 0x544BA78: _nc_lookup_bsd_terminfo_entry (read_bsd_terminfo.c:242) ==25119== by 0x544BDE7: _nc_read_bsd_terminfo_entry (read_bsd_terminfo.c:70) ==25119== by 0x544B1A2: _nc_read_entry (read_entry.c:526) ==25119== by 0x544A097: grab_entry (lib_setup.c:362) ==25119== by 0x544A097: _nc_setupterm (lib_setup.c:558) ==25119== by 0x5437787: tgetent (lib_termcap.c:90) ==25119== by 0x10EEC9: init_termcap (screen.c:90) ==25119== by 0x11031D: main (top.c:361) ==25119== ==25119== 1,024 bytes in 1 blocks are definitely lost in loss record 45 of 59 ==25119== at 0x501A1F0: calloc (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-openbsd.so) ==25119== by 0x544831F: _nc_copy_entry (alloc_entry.c:109) ==25119== by 0x5442889: enqueue (comp_parse.c:71) ==25119== by 0x5442889: _nc_read_entry_source (comp_parse.c:154) ==25119== by 0x544BA78: _nc_lookup_bsd_terminfo_entry (read_bsd_terminfo.c:242) ==25119== by 0x544BDE7: _nc_read_bsd_terminfo_entry (read_bsd_terminfo.c:70) ==25119== by 0x544B1A2: _nc_read_entry (read_entry.c:526) ==25119== by 0x544A097: grab_entry (lib_setup.c:362) ==25119== by 0x544A097: _nc_setupterm (lib_setup.c:558) ==25119== by 0x543AC0A: newterm (lib_newterm.c:142) ==25119== by 0x543AB39: initscr (lib_initscr.c:89) ==25119== by 0x110801: main (top.c:411) ==25119== ==25119== LEAK SUMMARY: ==25119== definitely lost: 2,048 bytes in 2 blocks ==25119== indirectly lost: 0 bytes in 0 blocks ==25119== possibly lost: 0 bytes in 0 blocks ==25119== still reachable: 687,648 bytes in 201 blocks ==25119== suppressed: 0 bytes in 0 blocks ==25119== Reachable blocks (those to which a pointer was found) are not shown. ==25119== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==25119== ==25119== For counts of detected and suppressed errors, rerun with: -v ==25119== Use --track-origins=yes to see where uninitialised values come from ==25119== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0) >8-------->8-------->8-------->8-------->8-------->8-------->8-------->8-------- You see ncurses somehow leaves heap memory at exit point. Other complex programs (using fork, chroot, network syscalls, etc.) are likely to fail. Please don't hesitate to ask questions/report problems to me. Thanks!