Valgrind reports memory leaks

Brad Hards bradh at frogmouth.net
Fri Jan 26 02:21:50 CET 2007


On Friday 26 January 2007 03:24, Pedro Lageira wrote:
> Hi,
>
> I'm using gcrypt library version 1.2.3. I made a very simple test
> program and run the Valgrind Memcheck (memory error detector) over it.
> It seems that gcry_ac_key_pair_generate() has a memory leak...
> I'm doing something wrong in my code? Can you help me?
It does appear to leak for me too. I'm using subversion (and the trace looks 
slightly different, but it is pointing to the same places).

I see:
==5740== 108 bytes in 1 blocks are definitely lost in loss record 2 of 4
==5740==    at 0x4005400: malloc (vg_replace_malloc.c:149)
==5740==    by 0x402AEFF: _gcry_private_malloc (stdmem.c:106)
==5740==    by 0x4027A67: _gcry_malloc (global.c:478)
==5740==    by 0x4027C92: gcry_malloc (global.c:500)
==5740==    by 0x402A6B2: gcry_sexp_find_token (sexp.c:420)
==5740==    by 0x4036731: _gcry_ac_key_pair_generate (ac.c:1734)
==5740==    by 0x40368A8: gcry_ac_key_pair_generate (ac.c:1781)
==5740==    by 0x804875E: main (in /home/bradh/junkcode/rsa-test/rsa-test)
==5740==
==5740==
==5740== 144 (128 direct, 16 indirect) bytes in 2 blocks are definitely lost 
in loss record 3 of 4
==5740==    at 0x40054FB: realloc (vg_replace_malloc.c:306)
==5740==    by 0x402AFCA: _gcry_private_realloc (stdmem.c:174)
==5740==    by 0x40278ED: gcry_realloc (global.c:545)
==5740==    by 0x4035045: _gcry_ac_data_set (ac.c:364)
==5740==    by 0x4035A9D: ac_data_extract (ac.c:1311)
==5740==    by 0x4036702: _gcry_ac_key_pair_generate (ac.c:1728)
==5740==    by 0x40368A8: gcry_ac_key_pair_generate (ac.c:1781)
==5740==    by 0x804875E: main (in /home/bradh/junkcode/rsa-test/rsa-test)

sexp.c:420 is:
newlist = gcry_malloc ( sizeof *newlist + n );
and the newlist never gets free'd.

ac.c:364 is:
ac_mpis = gcry_realloc (data->data, sizeof (*data->data) * (data->data_n +1));
and, again, no free that I can see.

The inside of the sexp code is a bit hairy for me, but if you don't try to 
disable secure memory, you may see the memory leak indications go away - they 
did for me.

Brad



More information about the Gcrypt-devel mailing list