Hello, I've been trying to use memcheck with my custom allocator, but I can't seem to get it to track leaks properly. In particular, (1) it doesn't appear to keep track of MEMPOOL_FREE requests, and (2) it doesn't even appear to detect leaks.
This issue was previously reported years ago on KDE (https://bugs.kde.org/show_bug.cgi?id=233298), and later asked about on Stack Overflow (https://stackoverflow.com/questions/30895018/custom-allocator-valgrind-shows-7-allocs-0-frees-no-leaks); however I'm still able to reproduce this issue on the latest version (3.19, compiled from latest source). Consider the following, adapted from the example shown on Stack Overflow: /* no-leak.c */ #include <valgrind/valgrind.h> #include <valgrind/memcheck.h> int main(int argc, char *argv[]) { char pool[100]; VALGRIND_CREATE_MEMPOOL(pool, 0, 0); VALGRIND_MAKE_MEM_NOACCESS(pool, 100); VALGRIND_MEMPOOL_ALLOC(pool, pool, 8); VALGRIND_MEMPOOL_FREE(pool, pool); // commented out VALGRIND_DESTROY_MEMPOOL(pool); // in leak.c return 0; } The main difference is that I also mark pool as NOACCESS; I understand that this is necessary so that pool is considered a superblock, from which memory pools may allocate memory. When I run this, it tells me I have 0 frees, yet it reports that there aren't any leaks: $ ./vg-in-place --leak-check=full --show-leak-kinds=all ~/no-leak ==3234114== Memcheck, a memory error detector ==3234114== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==3234114== Using Valgrind-3.19.0.GIT and LibVEX; rerun with -h for copyright info ==3234114== Command: /home/j-hui/no-leak ==3234114== ==3234114== ==3234114== HEAP SUMMARY: ==3234114== in use at exit: 0 bytes in 0 blocks ==3234114== total heap usage: 1 allocs, 0 frees, 8 bytes allocated ==3234114== ==3234114== All heap blocks were freed -- no leaks are possible ==3234114== ==3234114== For lists of detected and suppressed errors, rerun with: -s ==3234114== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Furthermore, when I comment out the VALGRIND_MEMPOOL_FREE and VALGRIND_DESTROY_MEMPOOL calls, it reports the exact same thing: $ ./vg-in-place --leak-check=full --show-leak-kinds=all ~/leak ==3234075== Memcheck, a memory error detector ==3234075== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==3234075== Using Valgrind-3.19.0.GIT and LibVEX; rerun with -h for copyright info ==3234075== Command: /home/j-hui/leak ==3234075== ==3234075== ==3234075== HEAP SUMMARY: ==3234075== in use at exit: 0 bytes in 0 blocks ==3234075== total heap usage: 1 allocs, 0 frees, 8 bytes allocated ==3234075== ==3234075== All heap blocks were freed -- no leaks are possible ==3234075== ==3234075== For lists of detected and suppressed errors, rerun with: -s ==3234075== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) Am I using this API incorrectly? If so, may someone please point out what I've done wrong? And if not, i.e., this is how the API should be used, are there any recommended workarounds? (The patch suggested in the KDE bug tracker, adding cmalloc_n_mallocs++ to various places, does not seem to fix things for me.) Thanks in advance! - John _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users