What could be the reason for this?
This is due to an error in valgrind. See the link to the valgrind debugging tracker in my comment on your answer.
From another link in my comment:
A quick search in the source code shows that MEMPOOL_ALLOC calls new_block, which increases cmalloc_n_mallocs, but there is no corresponding change in cmalloc_n_frees to MEMPOOL_FREE.
#include <valgrind/valgrind.h> int main(int argc, char *argv[]) { char pool[100]; VALGRIND_CREATE_MEMPOOL(pool, 0, 0); VALGRIND_MEMPOOL_ALLOC(pool, pool, 8); VALGRIND_MEMPOOL_FREE(pool, pool); VALGRIND_DESTROY_MEMPOOL(pool); return 0; }
$ gcc valgrind.c -g $ valgrind --leak-check=full --show-leak-kinds=all ./a.out ==10186== Memcheck, a memory error detector ==10186== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==10186== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==10186== Command: ./a.out ==10186== ==10186== ==10186== HEAP SUMMARY: ==10186== in use at exit: 0 bytes in 0 blocks ==10186== total heap usage: 1 allocs, 0 frees, 8 bytes allocated ==10186== ==10186== All heap blocks were freed -- no leaks are possible ==10186== ==10186== For counts of detected and suppressed errors, rerun with: -v ==10186== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) $
source share