From 86c24dd8321664a50a9c0ee4e54e21b21bbe46fc Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 5 Sep 2020 12:50:03 +0200 Subject: [PATCH] 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 --- core/taxonomy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; }