2015-06-17 12 views
6

sto lavorando un clone delle malloc (3) funzioni (malloc, realloc e free per ora).allocatore personalizzato: Valgrind mostra 7 Allocati, 0 frees, Nessuna perdita

Vorrei aggiungere supporto per Valgrind. Sto usando these docs. Tuttavia, dopo aver aggiunto le chiamate ai VALGRIND_MEMPOOL_FREE, VALGRIND_MEMPOOL_ALLOC e VALGRIND_CREATE_MEMPOOL macro, ottengo il seguente da 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 

Questo nonostante la mia e la mia realloc calling VALGRIND_MEMPOOL_FREEfree calling VALGRIND_MEMPOOL_FREE.

Quale potrebbe essere la causa di questo?

+4

See [http://valgrind.10908.n7.nabble.com/VALGRIND-MEMPOOL-FREE-not-reflected-in-heap-summary-td42789.html ] (http://valgrind.10908.n7.nabble.com/VALGRIND-MEMPOOL-FREE-not-reflected-in-heap-summary-td42789.html) e [https://bugs.kde.org/show_bug. cgi? id = 233.298] (https://bugs.kde.org/show_bug.cgi?id=233298). – 4566976

risposta

5

Quale potrebbe essere la causa di questo?

Ciò è dovuto a un errore in valgrind. Vedi lo link nel tracker dei bug di valgrind nel mio commento alla tua risposta.

Dall'altra link nel mio commento:

Una ricerca sommaria attraverso il codice sorgente indica che MEMPOOL_ALLOC chiamate new_block, che incrementa cmalloc_n_mallocs, ma non v'è alcun corrispondente variazione di cmalloc_n_frees in 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) 
$ 
+0

Questo è interessante, grazie per il suggerimento! Anche se non sono sicuro che sia effettivamente il problema. Vedo la variabile 'cmalloc_n_frees' che viene incrementata in 3.10, che è la versione in cui mi trovo (la versione del bug report è 3.5 e 3.6). 'cmalloc_n_frees' viene incrementato in' memcheck/mc_malloc_wrappers.c' alle righe 479/522 (fonte: http://valgrind.org/downloads/current.html). Inoltre, sono un po 'scettico su come il team di sviluppo di Valgrind possa aver perso un bug così ovvio. Dopotutto, lo standard 'malloc' sta andando bene con Valgrind. Non sto usando 'DESTROY_MEMPOOL' atm. È richiesto? – conradkdotcom

+0

@conradk La funzione rilevante è 'mempool_free' nella riga 861 dove' cmalloc_n_frees' non viene incrementato.'mempool_alloc' nella riga 832 chiama' new_block' dove il 'cmalloc_n_mallocs' viene incrementato, ma' mempool_free' non chiama 'handle_free' dove' cmalloc_n_frees' sarebbe stato incrementato. Il team di dev di valgrind non ha perso l'errore. È nel loro bug tracker, ma è strano che non sia stato ancora corretto dopo tanto tempo (più di cinque anni). – 4566976

+0

@conradk 'VALGRIND_DESTROY_MEMPOOL' non cambia nulla nell'output. Ho aggiunto un esempio con esso. – 4566976

0

Tratto da qui: http://valgrind.10908.n7.nabble.com/VALGRIND-MEMPOOL-FREE-not-reflected-in-heap-summary-td42789.html

Una ricerca sommaria attraverso il codice sorgente indica che MEMPOOL_ALLOC chiamate new_block, che incrementa cmalloc_n_mallocs, ma non c'è corrispondente variazione di cmalloc_n_frees in MEMPOOL_FREE. Ecco una patch che la incrementa alla fine di MEMPOOL_FREE. Questo dà a il comportamento che mi aspetto.

+0

'Ecco una patch' Dove? – Mast

+0

http://valgrind.10908.n7.nabble.com/attachment/42790/0/patch –

+0

Se copypaste da altre fonti ci si aspetta che questo testo venga contrassegnato come una citazione! – alk

Problemi correlati