Properly dispose the GSList chains

We forgot to free the link and the data, oops.
This commit is contained in:
LemonBoy 2017-10-21 17:38:06 +02:00
parent f4d811ddf5
commit cfc8c9f8e2
3 changed files with 17 additions and 5 deletions

View File

@ -218,6 +218,19 @@ GSList *gslist_remove_string (GSList *list, const char *str)
return list; return list;
} }
GSList *gslist_delete_string (GSList *list, const char *str, GDestroyNotify free_func)
{
GSList *l;
l = g_slist_find_custom(list, str, (GCompareFunc) g_strcmp0);
if (l != NULL) {
free_func(l->data);
return g_slist_delete_link(list, l);
}
return list;
}
/* `list' contains pointer to structure with a char* to string. */ /* `list' contains pointer to structure with a char* to string. */
char *gslistptr_to_string(GSList *list, int offset, const char *delimiter) char *gslistptr_to_string(GSList *list, int offset, const char *delimiter)
{ {

View File

@ -22,6 +22,7 @@ GSList *gslist_find_icase_string(GSList *list, const char *key);
GList *glist_find_string(GList *list, const char *key); GList *glist_find_string(GList *list, const char *key);
GList *glist_find_icase_string(GList *list, const char *key); GList *glist_find_icase_string(GList *list, const char *key);
GSList *gslist_remove_string (GSList *list, const char *str); GSList *gslist_remove_string (GSList *list, const char *str);
GSList *gslist_delete_string (GSList *list, const char *str, GDestroyNotify free_func);
void gslist_free_full (GSList *list, GDestroyNotify free_func); void gslist_free_full (GSList *list, GDestroyNotify free_func);

View File

@ -36,7 +36,7 @@ int cap_toggle (IRC_SERVER_REC *server, char *cap, int enable)
return TRUE; return TRUE;
} }
else if (!enable && gslist_find_string(server->cap_queue, cap)) { else if (!enable && gslist_find_string(server->cap_queue, cap)) {
server->cap_queue = gslist_remove_string(server->cap_queue, cap); server->cap_queue = gslist_delete_string(server->cap_queue, cap, g_free);
return TRUE; return TRUE;
} }
@ -135,8 +135,6 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
return; return;
} }
g_warning("%s -> %s", evt, list);
/* Strip the trailing whitespaces before splitting the string, some servers send responses with /* Strip the trailing whitespaces before splitting the string, some servers send responses with
* superfluous whitespaces that g_strsplit the interprets as tokens */ * superfluous whitespaces that g_strsplit the interprets as tokens */
caps = g_strsplit(g_strchomp(list), " ", -1); caps = g_strsplit(g_strchomp(list), " ", -1);
@ -214,7 +212,7 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
disable = (*caps[i] == '-'); disable = (*caps[i] == '-');
if (disable) if (disable)
server->cap_active = gslist_remove_string(server->cap_active, caps[i] + 1); server->cap_active = gslist_delete_string(server->cap_active, caps[i] + 1, g_free);
else else
server->cap_active = g_slist_prepend(server->cap_active, g_strdup(caps[i])); server->cap_active = g_slist_prepend(server->cap_active, g_strdup(caps[i]));
@ -265,7 +263,7 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
cap_emit_signal(server, "delete", key); cap_emit_signal(server, "delete", key);
/* The server removed this CAP, remove it from the list /* The server removed this CAP, remove it from the list
* of the active ones if we had requested it */ * of the active ones if we had requested it */
server->cap_active = gslist_remove_string(server->cap_active, key); server->cap_active = gslist_delete_string(server->cap_active, key, g_free);
} }
} }
else { else {