# HG changeset patch # User Mikael Berthe # Date 1165176937 -3600 # Node ID b9698c89f46d484a58686c03f2fa11641d45d789 # Parent 03bc225ad763dd5a6e6aee7d4b0e01fcbc093ef4 Fix memory leak in scr_handle_tab() diff -r 03bc225ad763 -r b9698c89f46d mcabber/src/compl.c --- a/mcabber/src/compl.c Sun Dec 03 19:29:54 2006 +0100 +++ b/mcabber/src/compl.c Sun Dec 03 21:15:37 2006 +0100 @@ -202,9 +202,14 @@ // compl_get_category_list() // Returns a slist of all words in the categories specified by the given flags -GSList *compl_get_category_list(guint cat_flags) +// Iff this function sets *dynlist to TRUE, then the caller must free the +// whole list after use. +GSList *compl_get_category_list(guint cat_flags, guint *dynlist) { GSList *sl_cat; + + *dynlist = FALSE; + // Look for category // XXX Actually that's not that simple... cat_flags can be a combination // of several flags! @@ -216,6 +221,7 @@ return ((category*)sl_cat->data)->words; // Handle dynamic SLists + *dynlist = TRUE; if (cat_flags == COMPL_GROUPNAME) { return compl_list(ROSTER_TYPE_GROUP); } @@ -229,6 +235,7 @@ return evs_geteventslist(TRUE); } + *dynlist = FALSE; return NULL; } diff -r 03bc225ad763 -r b9698c89f46d mcabber/src/compl.h --- a/mcabber/src/compl.h Sun Dec 03 19:29:54 2006 +0100 +++ b/mcabber/src/compl.h Sun Dec 03 21:15:37 2006 +0100 @@ -24,7 +24,7 @@ void compl_add_category_word(guint, const char *command); void compl_del_category_word(guint categ, const char *word); -GSList *compl_get_category_list(guint cat_flags); +GSList *compl_get_category_list(guint cat_flags, guint *dynlist); void new_completion(char *prefix, GSList *compl_cat); void done_completion(void); diff -r 03bc225ad763 -r b9698c89f46d mcabber/src/screen.c --- a/mcabber/src/screen.c Sun Dec 03 19:29:54 2006 +0100 +++ b/mcabber/src/screen.c Sun Dec 03 21:15:37 2006 +0100 @@ -2310,12 +2310,21 @@ } if (!completion_started) { - GSList *list = compl_get_category_list(compl_categ); + guint dynlist; + GSList *list = compl_get_category_list(compl_categ, &dynlist); if (list) { char *prefix = g_strndup(row, ptr_inputline-row); // Init completion new_completion(prefix, list); g_free(prefix); + // Free the list if it's a dynamic one + if (dynlist) { + GSList *slp; + for (slp = list; slp; slp = g_slist_next(slp)) + g_free(slp->data); + g_slist_free(list); + + } // Now complete cchar = complete(); if (cchar)