Fix memory leaks from results of gtk_tree_model_get().
authorAndrej Kacian <ticho@claws-mail.org>
Sat, 24 Feb 2018 22:27:35 +0000 (23:27 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Sat, 24 Feb 2018 22:27:35 +0000 (23:27 +0100)
G_TYPE_STRING values need to be freed, G_TYPE_PIXBUF
(or anything else derived from GObject) needs to be
unreferenced. This was forgotten in some places.

src/addrcustomattr.c
src/edittags.c
src/gtk/gtkutils.c
src/plugins/managesieve/sieve_manager.c
src/prefs_filtering.c
src/prefs_send.c
src/prefs_summaries.c
src/prefs_toolbar.c

index d3f97d5..6997f60 100644 (file)
@@ -103,6 +103,7 @@ static gint custom_attr_cmp_func (GtkTreeModel *model, GtkTreeIter *a,
                                                                  GtkTreeIter *b, gpointer userdata)
  {
        gchar *name1, *name2;
+       gint res;
 
        gtk_tree_model_get(model, a, CUSTOM_ATTR_NAME, &name1, -1);
        gtk_tree_model_get(model, b, CUSTOM_ATTR_NAME, &name2, -1);
@@ -113,7 +114,11 @@ static gint custom_attr_cmp_func (GtkTreeModel *model, GtkTreeIter *a,
        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 GtkListStore* custom_attr_window_create_data_store(void)
@@ -347,8 +352,10 @@ static gboolean find_attr_in_store(GtkTreeModel *model,
        if (g_utf8_collate(data->attr, attr)==0) {
                data->path = path; /* signal we found it */
                data->iter = *iter;
+               g_free(attr);
                return TRUE;
        }
+       g_free(attr);
        return FALSE; 
 }
 
@@ -580,6 +587,7 @@ static gboolean custom_attr_store_to_glist (GtkTreeModel *model,
        gtk_tree_model_get(model, iter, CUSTOM_ATTR_NAME, &attr, -1);
        if (attr) {
                store_to_glist = g_list_prepend(store_to_glist, g_strdup(attr));
+               g_free(attr);
        }
        return FALSE;
 }
index 1209dd0..c559102 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);
index 7aa5167..a933471 100644 (file)
@@ -1508,12 +1508,14 @@ gboolean gtkut_tree_model_text_iter_prev(GtkTreeModel *model,
                gtk_tree_model_get(model, &cur_iter, 0, &cur_value, -1);
 
                if (strcmp(text, cur_value) == 0) {
+                       g_free(cur_value);
                        if (count <= 0)
                                return FALSE;
 
                        return gtk_tree_model_iter_nth_child(model, iter, NULL, count - 1);
                }
 
+               g_free(cur_value);
                valid = gtk_tree_model_iter_next(model, &cur_iter);
                count++;
        }
index 7635c8b..8a9af4c 100644 (file)
@@ -186,11 +186,12 @@ static void filter_edit(GtkWidget *widget, SieveManagerPage *page)
 {
        SieveEditorPage *editor;
        SieveSession *session = page->active_session;
+       gchar *filter_name;
 
        if (!session)
                return;
 
-       gchar *filter_name = filters_list_get_selected_filter(page->filters_list);
+       filter_name = filters_list_get_selected_filter(page->filters_list);
        if (!filter_name)
                return;
 
@@ -202,6 +203,8 @@ static void filter_edit(GtkWidget *widget, SieveManagerPage *page)
                sieve_editor_load(editor,
                        (sieve_session_cb_fn)filter_got_load_error, page);
        }
+
+       g_free(filter_name);
 }
 
 static void filter_renamed(SieveSession *session, gboolean abort,
index d18aed1..8424ff8 100644 (file)
@@ -957,7 +957,6 @@ static void prefs_filtering_set_list(void)
                                        filtering.cond_list_view, row,
                                        &enabled, &name, &account_id);
                        prop = matcher_parser_get_filtering(filtering_str);
-                       g_free(filtering_str);
                        if (prop) {
                                prop->enabled = enabled;
                                if (prop->name != NULL)
@@ -968,7 +967,8 @@ static void prefs_filtering_set_list(void)
                                        g_slist_append(prefs_filtering, prop);
                        }
                }
-               
+
+               g_free(filtering_str);
                row++;
        }                               
        
@@ -1183,6 +1183,7 @@ static void prefs_filtering_substitute_cb(gpointer action, gpointer data)
        prefs_filtering_list_view_get_rule_info(
                        filtering.cond_list_view, selected_row,
                        &enabled, &name, &account_id);
+       g_free(name); /* We're not using this. */
        prop->enabled = enabled;
 
        prefs_filtering_list_view_set_row(selected_row, prop);
@@ -1263,6 +1264,7 @@ static void prefs_filtering_duplicate_cb(gpointer action, gpointer data)
        prefs_filtering_list_view_get_rule_info(
                        filtering.cond_list_view, selected_row,
                        &enabled, &name, &account_id);
+       g_free(name); /* We're not using this. */
        prop->enabled = enabled;
 
        prefs_filtering_list_view_set_row(-selected_row-2, prop);
index 53677eb..811e68b 100644 (file)
@@ -91,9 +91,11 @@ static gboolean _select_by_data_func(GtkTreeModel *model, GtkTreePath *path,
        gtk_tree_model_get(GTK_TREE_MODEL(model), iter, COMBOBOX_DATA, &curdata, -1);
        if ( data != NULL && curdata != NULL && !strcmp(data, curdata) ) {
                gtk_combo_box_set_active_iter(combobox, iter);
+               g_free(curdata);
                return TRUE;
        }
 
+       g_free(curdata);
        return FALSE;
 }
 
@@ -126,6 +128,8 @@ static gboolean _combobox_separator_func(GtkTreeModel *model,
 
        if( txt == NULL )
                return TRUE;
+
+       g_free(txt);
        return FALSE;
 }
 
index 27f07d5..16ae791 100644 (file)
@@ -889,6 +889,7 @@ static void date_format_select_row(GtkTreeView *list_view,
        strncpy(new_format, old_format, cur_pos);
        new_format[cur_pos] = '\0';
        strcat(new_format, format);
+       g_free(format);
        strcat(new_format, &old_format[cur_pos]);
 
        gtk_entry_set_text(GTK_ENTRY(datefmt_sample), new_format);
index 4586cf3..cc56483 100644 (file)
@@ -1319,7 +1319,8 @@ static void set_visible_if_not_text(GtkTreeViewColumn *col,
                                   -1);
                /* note getting a pixbuf from a tree model increases
                 * its refcount ... */
-               g_object_unref(pixbuf);
+               if (pixbuf != NULL)
+                       g_object_unref(pixbuf);
 
                g_object_set(renderer, "visible", TRUE, NULL);
                g_object_set(renderer, "pixbuf",  pixbuf, NULL);
@@ -1437,6 +1438,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
                                        ITEM_SEPARATOR);
                g_free(icon_text);
                g_free(descr);
+               if (pix != NULL)
+                       g_object_unref(pix);
 
                return TRUE;
        }
@@ -1473,6 +1476,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
 
                g_free(icon_text);
                g_free(descr);
+               if (pix != NULL)
+                       g_object_unref(pix);
 
                return TRUE;
        }
@@ -1488,6 +1493,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
 
                g_free(descr);
                g_free(icon_text);
+               if (pix != NULL)
+                       g_object_unref(pix);
                return TRUE;
        }
 
@@ -1513,6 +1520,8 @@ static gboolean set_list_selected(GtkTreeSelection *selector,
 
        g_free(icon_text);
        g_free(descr);
+       if (pix != NULL)
+               g_object_unref(pix);
 
        return TRUE;
 }
@@ -1548,6 +1557,8 @@ static void icon_chooser_ok_clicked(GtkButton *button,
        prefs_toolbar->item_icon_file = icon_file;
        gtk_button_set_image(GTK_BUTTON(prefs_toolbar->icon_button),
                             gtk_image_new_from_pixbuf(pix));
+       if (pix != NULL)
+               g_object_unref(pix);
 
        gtk_widget_destroy(prefs_toolbar->icon_chooser_win);
        prefs_toolbar->icon_chooser_win = NULL;