Estoy trabajando en un clon de las funciones malloc (3) ( malloc , realloc y free por ahora).
Me gustaría agregar soporte para Valgrind. Estoy usando estos documentos . Sin embargo, después de agregar llamadas a las VALGRIND_MEMPOOL_FREE , VALGRIND_MEMPOOL_ALLOC y VALGRIND_CREATE_MEMPOOL , obtengo lo siguiente de Valgrind:
==22303== HEAP SUMMARY: ==22303== in use at exit: 0 bytes in 0 blocks ==22303== total heap usage: 7 allocs, 0 frees, 2,039 bytes allocated ==22303== ==22303== All heap blocks were freed -- no leaks are possible Esto es a pesar de mi VALGRIND_MEMPOOL_FREE de llamadas realloc y mi llamada free VALGRIND_MEMPOOL_FREE .
Cuál podría ser la causa de esto ?
Cuál podría ser la causa de esto ?
Esto se debe a un error en valgrind. Vea el enlace al rastreador de errores de valgrind en mi comentario a su respuesta.
Del otro enlace en mi comentario:
Una búsqueda superficial en el código fuente indica que MEMPOOL_ALLOC llama a new_block, que incrementa cmalloc_n_mallocs, pero no hay un cambio correspondiente a cmalloc_n_frees en MEMPOOL_FREE.
/* valgrind.c */ #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) $Tomado de aquí: http://valgrind.10908.n7.nabble.com/VALGRIND-MEMPOOL-FREE-not-reflected-in-heap-summary-td42789.html
Una búsqueda superficial en el código fuente indica que MEMPOOL_ALLOC llama a new_block, que incrementa cmalloc_n_mallocs, pero no hay un cambio correspondiente a cmalloc_n_frees en MEMPOOL_FREE. Aquí hay un parche que lo incrementa al final de MEMPOOL_FREE. Esto me da el comportamiento que espero.