[evolution] Fix several memory leaks in the addressbook code



commit 1032b8bec7cbd71aed6ade40188f036f5b21d409
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 6 22:00:13 2019 +0200

    Fix several memory leaks in the addressbook code

 .../gui/contact-editor/e-contact-editor-dyntable.c |  7 +++++--
 .../gui/contact-editor/e-contact-editor.c          | 24 ++++++++++++++--------
 src/addressbook/gui/widgets/e-addressbook-model.c  |  2 +-
 src/addressbook/gui/widgets/e-addressbook-view.c   |  1 +
 .../gui/widgets/eab-contact-formatter.c            |  9 ++++----
 5 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/src/addressbook/gui/contact-editor/e-contact-editor-dyntable.c 
b/src/addressbook/gui/contact-editor/e-contact-editor-dyntable.c
index 7bfa11bc81..cee3fd6146 100644
--- a/src/addressbook/gui/contact-editor/e-contact-editor-dyntable.c
+++ b/src/addressbook/gui/contact-editor/e-contact-editor-dyntable.c
@@ -480,8 +480,6 @@ e_contact_editor_dyntable_fill_in_data (EContactEditorDynTable *dyntable)
        GtkTreeModel *store;
        GtkWidget *w;
        gboolean valid;
-       gchar *str_data;
-       gint int_data;
 
        class = E_CONTACT_EDITOR_DYNTABLE_GET_CLASS (dyntable);
        grid = GTK_GRID (dyntable);
@@ -489,6 +487,9 @@ e_contact_editor_dyntable_fill_in_data (EContactEditorDynTable *dyntable)
 
        valid = gtk_tree_model_get_iter_first (store, &iter);
        while (valid) {
+               gchar *str_data = NULL;
+               gint int_data;
+
                gtk_tree_model_get (store, &iter,
                                DYNTABLE_STORE_COLUMN_ENTRY_STRING, &str_data,
                                DYNTABLE_STORE_COLUMN_SELECTED_ITEM, &int_data,
@@ -503,6 +504,8 @@ e_contact_editor_dyntable_fill_in_data (EContactEditorDynTable *dyntable)
                w = gtk_grid_get_child_at (grid, col + 1, row);
                class->widget_fill (dyntable, w, str_data);
 
+               g_free (str_data);
+
                valid = gtk_tree_model_iter_next (store, &iter);
 
                if (valid && pos >= dyntable->priv->max_entries) {
diff --git a/src/addressbook/gui/contact-editor/e-contact-editor.c 
b/src/addressbook/gui/contact-editor/e-contact-editor.c
index c4d194ea39..c8b08a9438 100644
--- a/src/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/src/addressbook/gui/contact-editor/e-contact-editor.c
@@ -1032,7 +1032,7 @@ extract_email (EContactEditor *editor)
 
        valid = gtk_tree_model_get_iter_first (tree_model, &iter);
        while (valid) {
-               gchar *address;
+               gchar *address = NULL;
                gint   location;
                EVCardAttribute *attr;
 
@@ -1057,6 +1057,8 @@ extract_email (EContactEditor *editor)
 
                attr_list = g_list_prepend (attr_list, attr);
 
+               g_free (address);
+
                valid = gtk_tree_model_iter_next (tree_model, &iter);
        }
        attr_list = g_list_reverse (attr_list);
@@ -1221,7 +1223,7 @@ extract_phone (EContactEditor *editor)
        valid = gtk_tree_model_get_iter_first (tree_model, &iter);
        while (valid) {
                gint phone_type;
-               gchar *phone;
+               gchar *phone = NULL;
                EVCardAttribute *attr;
 
                gtk_tree_model_get (tree_model,&iter,
@@ -1248,6 +1250,8 @@ extract_phone (EContactEditor *editor)
 
                tel_attr_list = g_list_prepend (tel_attr_list, attr);
 
+               g_free (phone);
+
                valid = gtk_tree_model_iter_next (tree_model, &iter);
        }
 
@@ -1451,7 +1455,7 @@ extract_sip (EContactEditor *editor)
        valid = gtk_tree_model_get_iter_first (tree_model, &iter);
        while (valid) {
                gint sip_type;
-               gchar *sip;
+               gchar *sip = NULL;
                EVCardAttribute *attr;
 
                gtk_tree_model_get (tree_model,&iter,
@@ -1473,6 +1477,8 @@ extract_sip (EContactEditor *editor)
 
                sip_attr_list = g_list_prepend (sip_attr_list, attr);
 
+               g_free (sip);
+
                valid = gtk_tree_model_iter_next (tree_model, &iter);
        }
 
@@ -1642,7 +1648,7 @@ check_address_for_data (EContactEditor *editor,
        gboolean has_data = FALSE;
        EContactAddress *address;
 
-       address = g_new0 (EContactAddress, 1);
+       address = e_contact_address_new ();
 
        extract_address_from_gui (editor, address, record);
        if (!STRING_IS_EMPTY (address->street)   ||
@@ -1655,7 +1661,7 @@ check_address_for_data (EContactEditor *editor,
                has_data = TRUE;
        }
 
-       g_free (address);
+       e_contact_address_free (address);
 
        return has_data;
 }
@@ -2142,7 +2148,7 @@ extract_im (EContactEditor *editor)
        while (valid) {
                gint             service_type;
                gint             slot;
-               gchar           *im_name;
+               gchar           *im_name = NULL;
                EVCardAttribute *attr;
                const EABTypeLabel *im_service = eab_get_im_type_labels (&service_type);
 
@@ -2169,6 +2175,8 @@ extract_im (EContactEditor *editor)
 
                attr_list = g_list_prepend (attr_list, attr);
 
+               g_free (im_name);
+
                valid = gtk_tree_model_iter_next (tree_model, &iter);
        }
        attr_list = g_list_reverse (attr_list);
@@ -2506,7 +2514,7 @@ extract_address_record (EContactEditor *editor,
 {
        EContactAddress *address;
 
-       address = g_new0 (EContactAddress, 1);
+       address = e_contact_address_new ();
 
        extract_address_from_gui (editor, address, record);
        if (!STRING_IS_EMPTY (address->street)   ||
@@ -2524,7 +2532,7 @@ extract_address_record (EContactEditor *editor,
                set_address_label (editor->priv->contact, address_labels[record], NULL);
        }
 
-       g_boxed_free (e_contact_address_get_type (), address);
+       e_contact_address_free (address);
 }
 
 static void
diff --git a/src/addressbook/gui/widgets/e-addressbook-model.c 
b/src/addressbook/gui/widgets/e-addressbook-model.c
index 0e3d93c3bd..1153942db1 100644
--- a/src/addressbook/gui/widgets/e-addressbook-model.c
+++ b/src/addressbook/gui/widgets/e-addressbook-model.c
@@ -255,7 +255,7 @@ view_remove_contact_cb (EBookClientView *client_view,
        }
 
        g_signal_emit (model, signals[CONTACTS_REMOVED], 0, indices);
-       g_array_free (indices, FALSE);
+       g_array_free (indices, TRUE);
 
        update_folder_bar_message (model);
 }
diff --git a/src/addressbook/gui/widgets/e-addressbook-view.c 
b/src/addressbook/gui/widgets/e-addressbook-view.c
index 445a318d05..dfe4c98ecc 100644
--- a/src/addressbook/gui/widgets/e-addressbook-view.c
+++ b/src/addressbook/gui/widgets/e-addressbook-view.c
@@ -1481,6 +1481,7 @@ e_addressbook_view_delete_selection (EAddressbookView *view,
                e_table_set_cursor_row (E_TABLE (etable), row);
        }
        g_slist_free_full (list, (GDestroyNotify) g_object_unref);
+       g_free (name);
 }
 
 void
diff --git a/src/addressbook/gui/widgets/eab-contact-formatter.c 
b/src/addressbook/gui/widgets/eab-contact-formatter.c
index ece9e5447c..d2666f6e5f 100644
--- a/src/addressbook/gui/widgets/eab-contact-formatter.c
+++ b/src/addressbook/gui/widgets/eab-contact-formatter.c
@@ -267,7 +267,7 @@ render_table_row (GString *buffer,
                   const gchar *icon,
                   guint html_flags)
 {
-       const gchar *icon_html;
+       gchar *icon_html = NULL;
        gchar *value;
 
        if (html_flags)
@@ -278,7 +278,7 @@ render_table_row (GString *buffer,
        if (icon && icon_available (icon)) {
                icon_html = g_strdup_printf ("<img src=\"gtk-stock://%s\" width=\"16px\" height=\"16px\" />", 
icon);
        } else {
-               icon_html = "";
+               icon_html = NULL;
        }
 
        if (TEXT_IS_RIGHT_TO_LEFT) {
@@ -288,7 +288,7 @@ render_table_row (GString *buffer,
                        "<th align=\"right\" valign=\"top\" width=\"100\" nowrap>:%s</th>"
                        "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">%s</td>"
                        "</tr>",
-                       value, label, icon_html);
+                       value, label, icon_html ? icon_html : "");
        } else {
                g_string_append_printf (
                        buffer, "<tr>"
@@ -296,11 +296,12 @@ render_table_row (GString *buffer,
                        "<th valign=\"top\" width=\"100\" nowrap>%s:</th>"
                        "<td valign=\"top\">%s</td>"
                        "</tr>",
-                       icon_html, label, value);
+                       icon_html ? icon_html : "", label, value);
        }
 
        if (html_flags)
                g_free (value);
+       g_free (icon_html);
 }
 
 /* Returns NULL if no replace had been done (and


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]