mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
15de7f0b71
commit
3478943f2f
4 changed files with 10 additions and 11 deletions
10
taxonomy.c
10
taxonomy.c
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue