profanity-im / profanity

Ncurses based XMPP client
https://profanity-im.github.io/
Other
1.33k stars 188 forks source link

Fix mem leak in `conf_string_list_add` #1932

Closed H3rnand3zzz closed 1 year ago

H3rnand3zzz commented 1 year ago

See commit message.

jubalh commented 1 year ago

I checked the MUC and saw that @sjaeckel diff looked like:

       ```
       diff --git a/src/config/conflists.c b/src/config/conflists.c
       index 4032878e..838b611e 100644
       --- a/src/config/conflists.c
       +++ b/src/config/conflists.c
       @@ -51,3 +51,3 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con
            gsize length;
       -    auto_gcharv gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
       +    gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);

       @@ -62,2 +62,3 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con
                if (strcmp(list[i], item) == 0) {
       +            g_strfreev(list);
                    return FALSE;
       @@ -69,3 +70,3 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con
            for (gsize i = 0; i < length; ++i) {  
       -        new_list[i] = g_strdup(list[i]);
       +        new_list[i] = list[i];
            }
       @@ -73,2 +74,3 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con
            new_list[length + 1] = NULL;
       +    g_free(list);

       ```
H3rnand3zzz commented 1 year ago

The solution has been improved.

sjaeckel commented 1 year ago

The solution has been improved.

Indeed, looks very good now!