changeset 1076:b9698c89f46d

Fix memory leak in scr_handle_tab()
author Mikael Berthe <mikael@lilotux.net>
date Sun, 03 Dec 2006 21:15:37 +0100
parents 03bc225ad763
children c51ca5225516
files mcabber/src/compl.c mcabber/src/compl.h mcabber/src/screen.c
diffstat 3 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
--- 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);
--- 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)