diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-07-13 07:09:55 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-07-13 07:09:55 -0700 |
commit | 3478943f2ff5fae36d59667ffed33b9494d22acd (patch) | |
tree | 55271a007c085c1897563e9ec79a42ca570ed53c /taxonomy.c | |
parent | 15de7f0b716b4e3c28fee4f4ccbac4788a8d84b1 (diff) | |
download | subsurface-3478943f2ff5fae36d59667ffed33b9494d22acd.tar.gz |
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>
Diffstat (limited to 'taxonomy.c')
-rw-r--r-- | taxonomy.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/taxonomy.c b/taxonomy.c index b72616faf..40af9fd44 100644 --- a/taxonomy.c +++ b/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; } } |