From bd2821fafa15a3e5378f6aaf696d8d1bf0c18eb6 Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:27:04 +0100 Subject: [PATCH] Fix mem leak in `conf_string_list_add` Introduced in 1cf7973245b3331600a21c17eeee853e1cb3e3ec Issue reported and fix proposed by @sjaeckel --- src/config/conflists.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/config/conflists.c b/src/config/conflists.c index 4032878e..05d5d6ed 100644 --- a/src/config/conflists.c +++ b/src/config/conflists.c @@ -65,14 +65,16 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con } // Add item to the existing list - gchar** new_list = g_new(gchar*, length + 2); + const gchar** new_list = g_new(const gchar*, length + 2); for (gsize i = 0; i < length; ++i) { - new_list[i] = g_strdup(list[i]); + new_list[i] = list[i]; } - new_list[length] = g_strdup(item); + new_list[length] = item; new_list[length + 1] = NULL; - g_key_file_set_string_list(keyfile, group, key, (const gchar* const*)new_list, length + 1); + g_key_file_set_string_list(keyfile, group, key, new_list, length + 1); + + g_free(new_list); return TRUE; }