Fix memory handling for taxonomy data

The way we freed things and cleared out the variables potentially left
dangling data behind and could end up calling free on garbage data,
leading to random crashes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-07-13 07:09:55 -07:00
parent 15de7f0b71
commit 3478943f2f
4 changed files with 10 additions and 11 deletions

View file

@ -28,11 +28,13 @@ struct taxonomy *alloc_taxonomy()
return calloc(TC_NR_CATEGORIES, sizeof(struct taxonomy));
}
void free_taxonomy(struct taxonomy *t)
void free_taxonomy(struct taxonomy_data *t)
{
if (t) {
for (int i = 0; i < TC_NR_CATEGORIES; i++)
free((void *)t[i].value);
free(t);
for (int i = 0; i < t->nr; i++)
free((void *)t->category[i].value);
free(t->category);
t->category = NULL;
t->nr = 0;
}
}