summaryrefslogtreecommitdiffstats
path: root/core/taxonomy.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-05 12:50:03 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-09-06 12:59:54 -0700
commit86c24dd8321664a50a9c0ee4e54e21b21bbe46fc (patch)
tree76ba742792fc79cac6734d1db63dfcd5974e00c5 /core/taxonomy.c
parentb1a1dc36398530fa83038c9f71f480b9b955af22 (diff)
downloadsubsurface-86c24dd8321664a50a9c0ee4e54e21b21bbe46fc.tar.gz
cleanup: leak fix in taxonomy_set_country()
When overwriting a country, the old string was not freed. Fix this. Contains an unrelated coding-style fix: use braces if code block contains more than one line. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/taxonomy.c')
-rw-r--r--core/taxonomy.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/taxonomy.c b/core/taxonomy.c
index 1747a78cf..63c7fc507 100644
--- a/core/taxonomy.c
+++ b/core/taxonomy.c
@@ -65,9 +65,10 @@ void copy_taxonomy(const struct taxonomy_data *orig, struct taxonomy_data *copy)
int taxonomy_index_for_category(const struct taxonomy_data *t, enum taxonomy_category cat)
{
- for (int i = 0; i < t->nr; i++)
+ for (int i = 0; i < t->nr; i++) {
if (t->category[i].category == cat)
return i;
+ }
return -1;
}
@@ -90,6 +91,8 @@ void taxonomy_set_country(struct taxonomy_data *t, const char *country, enum tax
for (int i = 0; i < t->nr; i++) {
if (t->category[i].category == TC_COUNTRY) {
+ free((void *)t->category[i].value);
+ t->category[i].value = NULL;
idx = i;
break;
}