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>
This commit is contained in:
Berthold Stoeger 2020-09-05 12:50:03 +02:00 committed by Dirk Hohndel
parent b1a1dc3639
commit 86c24dd832

View file

@ -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;
}