Memory leak in gcry_ac_key_destroy?

Manu Srivastava mastermanu2004 at gmail.com
Sun Jul 20 00:21:15 CEST 2008


Hi,

In the function _gcry_ac_key_destroy, Is there a reason that:
gcry_free(key->data->data) is omitted?

Furthermore, for each element in key->data->data, shouldn't there also
be a gcry_free(key->data->data[i].name)?

Finally, is it reasonable to replace the if(key->data) block with
gcry_ac_data_destroy(key->data)?

I ask because I am using the ac library for encrypting messages and I
need to make sure all memory leaks are plugged.
According to valgrind there is a memory leak tied to memory allocated
in gcry_ac_key_init, and when I place the above two lines in
the destruction function, it fixes it.

-manu

ac.c (~ line 1683)
void
_gcry_ac_key_destroy (gcry_ac_key_t key)
{
  unsigned int i;

  if (key)
    {
      if (key->data)
        {
          for (i = 0; i < key->data->data_n; i++) {
                if (key->data->data[i].mpi != NULL) {
                        gcry_mpi_release (key->data->data[i].mpi);
                        //gcry_free(key->data->data[i].name); *should
insert this*?
                }
          }
          //gcry_free(key->data->data); *should insert this*?
          gcry_free (key->data);
        }
      gcry_free (key);
    }
}



More information about the Gcrypt-devel mailing list