Free hashmap to eliminate memory leaks

This commit is contained in:
Greg Sjaardema 2016-03-24 06:36:20 -06:00
parent d5cb4b9e3e
commit a248e0dfbe
3 changed files with 12 additions and 6 deletions

View File

@ -196,10 +196,13 @@ void
free_NC_dimarrayV(NC_dimarray *ncap)
{
assert(ncap != NULL);
if(ncap->nalloc == 0)
return;
NC_hashmapDelete(ncap->hashmap);
ncap->hashmap = NULL;
assert(ncap->value != NULL);
free_NC_dimarrayV0(ncap);

View File

@ -210,6 +210,8 @@ long NC_hashmapCount(NC_hashmap* hash)
void NC_hashmapDelete(NC_hashmap* hash)
{
free(hash->table);
free(hash);
if (hash) {
free(hash->table);
free(hash);
}
}

View File

@ -205,6 +205,9 @@ free_NC_vararrayV(NC_vararray *ncap)
if(ncap->nalloc == 0)
return;
NC_hashmapDelete(ncap->hashmap);
ncap->hashmap = NULL;
assert(ncap->value != NULL);
free_NC_vararrayV0(ncap);
@ -333,10 +336,8 @@ NC_hvarid
int
NC_findvar(const NC_vararray *ncap, const char *uname, NC_var **varpp)
{
int hash_var_id;
NC_var **loc;
int hash_var_id;
uint32_t shash;
int varid;
char *name;
assert(ncap != NULL);