Fix memory leaks from results of gtk_tree_model_get().
[claws.git] / src / edittags.c
index a107c158e07d27dc0cb2a8b28cad7d58c8749760..c559102a77352d4ffb5bca30b36d095d19271255 100644 (file)
@@ -59,6 +59,7 @@ enum {
 static gint tag_cmp_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
  {
        gchar *name1, *name2;
+       gint res;
 
        gtk_tree_model_get(model, a, TAG_NAME, &name1, -1);
        gtk_tree_model_get(model, b, TAG_NAME, &name2, -1);
@@ -69,7 +70,11 @@ static gint tag_cmp_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, g
        if (name2 == NULL)
                return 1;
        
-       return g_utf8_collate(name1,name2);
+       res = g_utf8_collate(name1,name2);
+       g_free(name1);
+       g_free(name2);
+
+       return res;
 }
 
 static void apply_window_create(void);
@@ -215,7 +220,8 @@ static void apply_popup_delete (GtkAction *action, gpointer data)
 
        if (alertpanel(_("Delete tag"),
                       _("Do you really want to delete this tag?"),
-                      GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL) != G_ALERTALTERNATE)
+                      GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL,
+                                        ALERTFOCUS_FIRST) != G_ALERTALTERNATE)
                return;
 
        APPLYWINDOW_LOCK();
@@ -225,6 +231,13 @@ static void apply_popup_delete (GtkAction *action, gpointer data)
        gtk_tree_model_get(model, &sel,
                           TAG_DATA, &id,
                           -1);
+
+       /* Even though this is not documented, gtk_tree_model_get()
+        * seems to invalidate the GtkTreeIter that is passed to it,
+        * so we need to reacquire it. */
+       if (!gtk_tree_selection_get_selected(selection, NULL, &sel))
+               return;
+
        gtk_list_store_remove(GTK_LIST_STORE(model), &sel);
        if (mainwindow_get_mainwindow() != NULL)
                summaryview = mainwindow_get_mainwindow()->summaryview;
@@ -243,7 +256,8 @@ static void apply_popup_delete_all (GtkAction *action, gpointer data)
        
        if (alertpanel(_("Delete all tags"),
                       _("Do you really want to delete all tags?"),
-                      GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL) != G_ALERTALTERNATE)
+                      GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL,
+                                        ALERTFOCUS_FIRST) != G_ALERTALTERNATE)
                return;
 
        APPLYWINDOW_LOCK();