[evolution/evolution-3-12] Fix various memory leaks and invalid memory usages



commit ffa74c5b96c03d63518d48dfaba09fbac30590a5
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 7 07:36:54 2014 +0200

    Fix various memory leaks and invalid memory usages

 calendar/gui/e-cal-model.c            |    4 +-
 calendar/gui/ea-cal-view-event.c      |   87 +++++----------------------------
 calendar/gui/ea-day-view-main-item.c  |   17 ++-----
 calendar/gui/ea-week-view-main-item.c |   17 ++-----
 calendar/gui/print.c                  |    7 ++-
 e-util/e-misc-utils.c                 |    1 +
 e-util/e-table-sorter.c               |    2 +
 e-util/e-table-sorting-utils.c        |   15 +++--
 e-util/ea-calendar-item.c             |   17 ++-----
 e-util/ea-cell-table.c                |    1 +
 e-util/gal-a11y-e-text.h              |    4 --
 plugins/save-calendar/csv-format.c    |    2 +-
 plugins/save-calendar/ical-format.c   |    2 +-
 plugins/save-calendar/rdf-format.c    |    2 +-
 plugins/save-calendar/save-calendar.c |   15 ++---
 15 files changed, 57 insertions(+), 136 deletions(-)
---
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index a27bef9..f7f3d6e 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -1502,10 +1502,10 @@ cal_model_duplicate_value (ETableModel *etm,
 
        switch (col) {
        case E_CAL_MODEL_FIELD_CATEGORIES :
-       case E_CAL_MODEL_FIELD_CLASSIFICATION :
        case E_CAL_MODEL_FIELD_DESCRIPTION :
        case E_CAL_MODEL_FIELD_SUMMARY :
                return g_strdup (value);
+       case E_CAL_MODEL_FIELD_CLASSIFICATION :
        case E_CAL_MODEL_FIELD_HAS_ALARMS :
        case E_CAL_MODEL_FIELD_ICON :
        case E_CAL_MODEL_FIELD_COLOR :
@@ -1577,10 +1577,10 @@ cal_model_initialize_value (ETableModel *etm,
        switch (col) {
        case E_CAL_MODEL_FIELD_CATEGORIES :
                return g_strdup (priv->default_category ? priv->default_category:"");
-       case E_CAL_MODEL_FIELD_CLASSIFICATION :
        case E_CAL_MODEL_FIELD_DESCRIPTION :
        case E_CAL_MODEL_FIELD_SUMMARY :
                return g_strdup ("");
+       case E_CAL_MODEL_FIELD_CLASSIFICATION :
        case E_CAL_MODEL_FIELD_DTSTART :
        case E_CAL_MODEL_FIELD_CREATED :
        case E_CAL_MODEL_FIELD_LASTMODIFIED :
diff --git a/calendar/gui/ea-cal-view-event.c b/calendar/gui/ea-cal-view-event.c
index 60f7b7d..1c915cd 100644
--- a/calendar/gui/ea-cal-view-event.c
+++ b/calendar/gui/ea-cal-view-event.c
@@ -25,13 +25,20 @@
 
 #include <glib/gi18n.h>
 
+#include "e-util/gal-a11y-e-text.h"
+
 #include "ea-cal-view-event.h"
 #include "ea-calendar-helpers.h"
 #include "ea-day-view.h"
 #include "ea-week-view.h"
 
-static void    ea_cal_view_event_class_init    (EaCalViewEventClass *klass);
-static void    ea_cal_view_event_init          (EaCalViewEvent *a11y);
+static void    atk_component_interface_init    (AtkComponentIface *iface);
+static void    atk_action_interface_init       (AtkActionIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (EaCalViewEvent, ea_cal_view_event, GAL_A11Y_TYPE_E_TEXT,
+       G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
+       G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
+
 static void    ea_cal_view_event_dispose       (GObject *object);
 static const gchar *
                ea_cal_view_event_get_name      (AtkObject *accessible);
@@ -46,7 +53,6 @@ static AtkStateSet *
                ea_cal_view_event_ref_state_set (AtkObject *accessible);
 
 /* component interface */
-static void    atk_component_interface_init    (AtkComponentIface *iface);
 static void    ea_cal_view_get_extents         (AtkComponent *component,
                                                 gint *x,
                                                 gint *y,
@@ -54,7 +60,6 @@ static void   ea_cal_view_get_extents         (AtkComponent *component,
                                                 gint *height,
                                                 AtkCoordType coord_type);
 /* action interface */
-static void    atk_action_interface_init       (AtkActionIface *iface);
 static gboolean        ea_cal_view_event_do_action     (AtkAction *action,
                                                 gint i);
 static gint    ea_cal_view_event_get_n_actions (AtkAction *action);
@@ -69,72 +74,6 @@ static gint n_ea_cal_view_event_destroyed = 0;
 static void ea_cal_view_finalize (GObject *object);
 #endif
 
-static gpointer parent_class = NULL;
-
-GType
-ea_cal_view_event_get_type (void)
-{
-       static GType type = 0;
-       AtkObjectFactory *factory;
-       GTypeQuery query;
-       GType derived_atk_type;
-
-       if (!type) {
-               static GTypeInfo tinfo = {
-                       sizeof (EaCalViewEventClass),
-                       (GBaseInitFunc) NULL, /* base init */
-                       (GBaseFinalizeFunc) NULL, /* base finalize */
-                       (GClassInitFunc) ea_cal_view_event_class_init, /* class init */
-                       (GClassFinalizeFunc) NULL, /* class finalize */
-                       NULL, /* class data */
-                       sizeof (EaCalViewEvent), /* instance size */
-                       0, /* nb preallocs */
-                       (GInstanceInitFunc) ea_cal_view_event_init, /* instance init */
-                       NULL /* value table */
-               };
-
-               static const GInterfaceInfo atk_component_info = {
-                       (GInterfaceInitFunc) atk_component_interface_init,
-                       (GInterfaceFinalizeFunc) NULL,
-                       NULL
-               };
-
-               static const GInterfaceInfo atk_action_info = {
-                       (GInterfaceInitFunc) atk_action_interface_init,
-                       (GInterfaceFinalizeFunc) NULL,
-                       NULL
-               };
-
-               /*
-                * Figure out the size of the class and instance
-                * we are run-time deriving from (atk object for E_TEXT, in this case)
-                */
-
-               factory = atk_registry_get_factory (
-                       atk_get_default_registry (),
-                       E_TYPE_TEXT);
-               derived_atk_type = atk_object_factory_get_accessible_type (factory);
-               g_type_query (derived_atk_type, &query);
-
-               tinfo.class_size = query.class_size;
-               tinfo.instance_size = query.instance_size;
-
-               /* we inherit the component, text and other interfaces from E_TEXT */
-               type = g_type_register_static (
-                       derived_atk_type,
-                       "EaCalViewEvent", &tinfo, 0);
-               g_type_add_interface_static (
-                       type, ATK_TYPE_COMPONENT,
-                       &atk_component_info);
-               g_type_add_interface_static (
-                       type, ATK_TYPE_ACTION,
-                       &atk_action_info);
-
-       }
-
-       return type;
-}
-
 static void
 ea_cal_view_event_class_init (EaCalViewEventClass *klass)
 {
@@ -144,8 +83,6 @@ ea_cal_view_event_class_init (EaCalViewEventClass *klass)
        gobject_class->finalize = ea_cal_view_finalize;
 #endif
 
-       parent_class = g_type_class_peek_parent (klass);
-
        gobject_class->dispose = ea_cal_view_event_dispose;
 
        class->get_name = ea_cal_view_event_get_name;
@@ -171,7 +108,7 @@ ea_cal_view_event_init (EaCalViewEvent *a11y)
 #ifdef ACC_DEBUG
 static void ea_cal_view_finalize (GObject *object)
 {
-       G_OBJECT_CLASS (parent_class)->finalize (object);
+       G_OBJECT_CLASS (ea_cal_view_event_parent_class)->finalize (object);
 
        ++n_ea_cal_view_event_destroyed;
        printf (
@@ -265,7 +202,7 @@ ea_cal_view_event_dispose (GObject *object)
        }
 
        /* Chain up to parent's dispose() method. */
-       G_OBJECT_CLASS (parent_class)->dispose (object);
+       G_OBJECT_CLASS (ea_cal_view_event_parent_class)->dispose (object);
 }
 
 static const gchar *
@@ -317,7 +254,7 @@ ea_cal_view_event_get_name (AtkObject *accessible)
                alarm_string, recur_string, meeting_string);
        g_free (summary_string);
 
-       ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name_string);
+       ATK_OBJECT_CLASS (ea_cal_view_event_parent_class)->set_name (accessible, name_string);
 #ifdef ACC_DEBUG
        printf (
                "EvoAcc:  name for event accobj=%p, is %s\n",
diff --git a/calendar/gui/ea-day-view-main-item.c b/calendar/gui/ea-day-view-main-item.c
index 9396eef..2e456c9 100644
--- a/calendar/gui/ea-day-view-main-item.c
+++ b/calendar/gui/ea-day-view-main-item.c
@@ -576,9 +576,10 @@ ea_day_view_main_item_get_cell_data (EaDayViewMainItem *ea_main_item)
                cell_data = ea_cell_table_create (
                        day_view->rows,
                        e_day_view_get_days_shown (day_view), TRUE);
-               g_object_set_data (
+               g_object_set_data_full (
                        G_OBJECT (ea_main_item),
-                       "ea-day-view-cell-table", cell_data);
+                       "ea-day-view-cell-table", cell_data,
+                       (GDestroyNotify) ea_cell_table_destroy);
        }
        return cell_data;
 }
@@ -586,19 +587,11 @@ ea_day_view_main_item_get_cell_data (EaDayViewMainItem *ea_main_item)
 static void
 ea_day_view_main_item_destory_cell_data (EaDayViewMainItem *ea_main_item)
 {
-       EaCellTable *cell_data;
-
        g_return_if_fail (ea_main_item);
 
-       cell_data = g_object_get_data (
+       g_object_set_data (
                G_OBJECT (ea_main_item),
-               "ea-day-view-cell-table");
-       if (cell_data) {
-               g_object_set_data (
-                       G_OBJECT (ea_main_item),
-                       "ea-day-view-cell-table", NULL);
-               ea_cell_table_destroy (cell_data);
-       }
+               "ea-day-view-cell-table", NULL);
 }
 
 /* Atk Component Interface */
diff --git a/calendar/gui/ea-week-view-main-item.c b/calendar/gui/ea-week-view-main-item.c
index 96ed04e..6332540 100644
--- a/calendar/gui/ea-week-view-main-item.c
+++ b/calendar/gui/ea-week-view-main-item.c
@@ -574,9 +574,10 @@ ea_week_view_main_item_get_cell_data (EaWeekViewMainItem *ea_main_item)
                "ea-week-view-cell-table");
        if (!cell_data) {
                cell_data = ea_cell_table_create (weeks_shown, 7, TRUE);
-               g_object_set_data (
+               g_object_set_data_full (
                        G_OBJECT (ea_main_item),
-                       "ea-week-view-cell-table", cell_data);
+                       "ea-week-view-cell-table", cell_data,
+                       (GDestroyNotify) ea_cell_table_destroy);
        }
        return cell_data;
 }
@@ -584,19 +585,11 @@ ea_week_view_main_item_get_cell_data (EaWeekViewMainItem *ea_main_item)
 static void
 ea_week_view_main_item_destory_cell_data (EaWeekViewMainItem *ea_main_item)
 {
-       EaCellTable *cell_data;
-
        g_return_if_fail (ea_main_item);
 
-       cell_data = g_object_get_data (
+       g_object_set_data (
                G_OBJECT (ea_main_item),
-               "ea-week-view-cell-table");
-       if (cell_data) {
-               g_object_set_data (
-                       G_OBJECT (ea_main_item),
-                       "ea-week-view-cell-table", NULL);
-               ea_cell_table_destroy (cell_data);
-       }
+               "ea-week-view-cell-table", NULL);
 }
 
 /* Atk Component Interface */
diff --git a/calendar/gui/print.c b/calendar/gui/print.c
index 6546688..8ce1fa1 100644
--- a/calendar/gui/print.c
+++ b/calendar/gui/print.c
@@ -1712,6 +1712,8 @@ print_day_details (GtkPrintContext *context,
        /* use font like with 30 minutes time division */
        rows_with_30_mins = (pdi.end_hour - pdi.start_hour) * (60 / 30);
 
+       pango_font_description_free (font);
+
        /* print the short events. */
        if (top > bottom)
                max_font_size = ((top - bottom) / rows_with_30_mins) - 4;
@@ -2883,6 +2885,8 @@ print_work_week_day_details (GtkPrintContext *context,
        /* use font like with 30 minutes time division */
        rows_with_30_mins = (pdi.end_hour - pdi.start_hour) * (60 / 30);
 
+       pango_font_description_free (font);
+
        /* print the short events. */
        if (top > bottom)
                max_font_size = ((top - bottom) / rows_with_30_mins) - 4;
@@ -3517,9 +3521,10 @@ print_comp_draw_real (GtkPrintOperation *operation,
                print_text (
                        context, font, title, PANGO_ALIGN_CENTER, 0.0, width,
                        0.1, header_size - 0.1);
-               pango_font_description_free (font);
        }
 
+       pango_font_description_free (font);
+
        top += header_size + 30;
 
        /* Summary */
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index 98c6fe7..b9a1a59 100644
--- a/e-util/e-misc-utils.c
+++ b/e-util/e-misc-utils.c
@@ -1474,6 +1474,7 @@ e_utils_shade_color (const GdkRGBA *a,
        b->red = red;
        b->green = green;
        b->blue = blue;
+       b->alpha = a->alpha;
 }
 
 static gint
diff --git a/e-util/e-table-sorter.c b/e-util/e-table-sorter.c
index 6087b3c..fe0e018 100644
--- a/e-util/e-table-sorter.c
+++ b/e-util/e-table-sorter.c
@@ -354,6 +354,8 @@ table_sorter_dispose (GObject *object)
        g_clear_object (&table_sorter->full_header);
        g_clear_object (&table_sorter->source);
 
+       table_sorter_clean (table_sorter);
+
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_table_sorter_parent_class)->dispose (object);
 }
diff --git a/e-util/e-table-sorting-utils.c b/e-util/e-table-sorting-utils.c
index 972a3fc..4795ae2 100644
--- a/e-util/e-table-sorting-utils.c
+++ b/e-util/e-table-sorting-utils.c
@@ -49,6 +49,7 @@ etsu_compare (ETableModel *source,
        for (j = 0; j < sort_count; j++) {
                ETableColumnSpecification *spec;
                ETableCol *col;
+               gpointer value1, value2;
 
                spec = e_table_sort_info_sorting_get_nth (
                        sort_info, j, &sort_type);
@@ -59,12 +60,14 @@ etsu_compare (ETableModel *source,
                        col = e_table_header_get_column (full_header, last);
                }
 
-               comp_val = (*col->compare) (
-                       e_table_model_value_at (
-                               source, col->spec->compare_col, row1),
-                       e_table_model_value_at (
-                               source, col->spec->compare_col, row2),
-                       cmp_cache);
+               value1 = e_table_model_value_at (source, col->spec->compare_col, row1);
+               value2 = e_table_model_value_at (source, col->spec->compare_col, row2);
+
+               comp_val = (*col->compare) (value1, value2, cmp_cache);
+
+               e_table_model_free_value (source, col->spec->compare_col, value1);
+               e_table_model_free_value (source, col->spec->compare_col, value2);
+
                if (comp_val != 0)
                        break;
        }
diff --git a/e-util/ea-calendar-item.c b/e-util/ea-calendar-item.c
index cc7d4d5..f32d655 100644
--- a/e-util/ea-calendar-item.c
+++ b/e-util/ea-calendar-item.c
@@ -1097,9 +1097,10 @@ ea_calendar_item_get_cell_data (EaCalendarItem *ea_calitem)
                        n_cells / EA_CALENDAR_COLUMN_NUM,
                        EA_CALENDAR_COLUMN_NUM,
                        FALSE);
-               g_object_set_data (
+               g_object_set_data_full (
                        G_OBJECT (ea_calitem),
-                       "ea-calendar-cell-table", cell_data);
+                       "ea-calendar-cell-table", cell_data,
+                       (GDestroyNotify) ea_cell_table_destroy);
        }
        return cell_data;
 }
@@ -1107,19 +1108,11 @@ ea_calendar_item_get_cell_data (EaCalendarItem *ea_calitem)
 static void
 ea_calendar_item_destory_cell_data (EaCalendarItem *ea_calitem)
 {
-       EaCellTable *cell_data;
-
        g_return_if_fail (ea_calitem);
 
-       cell_data = g_object_get_data (
+       g_object_set_data (
                G_OBJECT (ea_calitem),
-               "ea-calendar-cell-table");
-       if (cell_data) {
-               g_object_set_data (
-                       G_OBJECT (ea_calitem),
-                       "ea-calendar-cell-table", NULL);
-               ea_cell_table_destroy (cell_data);
-       }
+               "ea-calendar-cell-table", NULL);
 }
 
 static gboolean
diff --git a/e-util/ea-cell-table.c b/e-util/ea-cell-table.c
index 3a3fabd..dd1e647 100644
--- a/e-util/ea-cell-table.c
+++ b/e-util/ea-cell-table.c
@@ -78,6 +78,7 @@ ea_cell_table_destroy (EaCellTable *cell_data)
                        g_object_unref (cell_data->cells[index]);
 
        g_free (cell_data->cells);
+       g_free (cell_data);
 }
 
 gpointer
diff --git a/e-util/gal-a11y-e-text.h b/e-util/gal-a11y-e-text.h
index a53b812..58a21fe 100644
--- a/e-util/gal-a11y-e-text.h
+++ b/e-util/gal-a11y-e-text.h
@@ -20,10 +20,6 @@
  *
  */
 
-#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
-#error "Only <e-util/e-util.h> should be included directly."
-#endif
-
 #ifndef __GAL_A11Y_E_TEXT_H__
 #define __GAL_A11Y_E_TEXT_H__
 
diff --git a/plugins/save-calendar/csv-format.c b/plugins/save-calendar/csv-format.c
index 990c27b..650d01b 100644
--- a/plugins/save-calendar/csv-format.c
+++ b/plugins/save-calendar/csv-format.c
@@ -622,7 +622,7 @@ create_options_widget (FormatHandler *handler)
 
 FormatHandler *csv_format_handler_new (void)
 {
-       FormatHandler *handler = g_new (FormatHandler, 1);
+       FormatHandler *handler = g_new0 (FormatHandler, 1);
 
        handler->isdefault = FALSE;
        handler->combo_label = _("Comma separated values (.csv)");
diff --git a/plugins/save-calendar/ical-format.c b/plugins/save-calendar/ical-format.c
index a390eb2..617405f 100644
--- a/plugins/save-calendar/ical-format.c
+++ b/plugins/save-calendar/ical-format.c
@@ -177,7 +177,7 @@ do_save_calendar_ical (FormatHandler *handler,
 FormatHandler *
 ical_format_handler_new (void)
 {
-       FormatHandler *handler = g_new (FormatHandler, 1);
+       FormatHandler *handler = g_new0 (FormatHandler, 1);
 
        handler->isdefault = TRUE;
        handler->combo_label = _("iCalendar (.ics)");
diff --git a/plugins/save-calendar/rdf-format.c b/plugins/save-calendar/rdf-format.c
index f89b770..50abdca 100644
--- a/plugins/save-calendar/rdf-format.c
+++ b/plugins/save-calendar/rdf-format.c
@@ -379,7 +379,7 @@ do_save_calendar_rdf (FormatHandler *handler,
 FormatHandler *
 rdf_format_handler_new (void)
 {
-       FormatHandler *handler = g_new (FormatHandler, 1);
+       FormatHandler *handler = g_new0 (FormatHandler, 1);
 
        handler->isdefault = FALSE;
        handler->combo_label = _("RDF (.rdf)");
diff --git a/plugins/save-calendar/save-calendar.c b/plugins/save-calendar/save-calendar.c
index 9d02ab8..c5d373e 100644
--- a/plugins/save-calendar/save-calendar.c
+++ b/plugins/save-calendar/save-calendar.c
@@ -95,8 +95,7 @@ on_type_combobox_changed (GtkComboBox *combobox,
 }
 
 static void
-format_handlers_foreach_free (gpointer data,
-                              gpointer user_data)
+format_handlers_foreach_free (gpointer data)
 {
        FormatHandler *handler = data;
 
@@ -127,7 +126,7 @@ ask_destination_and_save (ESourceSelector *selector,
        GtkWidget *dialog = NULL;
        gchar *dest_uri = NULL;
 
-       GList *format_handlers = NULL;
+       GList *format_handlers = NULL, *link;
 
        /* The available formathandlers */
        format_handlers = g_list_append (format_handlers,
@@ -153,8 +152,9 @@ ask_destination_and_save (ESourceSelector *selector,
                GTK_CELL_LAYOUT (combo),
                renderer, "text", DEST_NAME_COLUMN, NULL);
 
-       while (format_handlers) {
-               handler = format_handlers->data;
+       for (link = format_handlers; link; link = g_list_next (link)) {
+               handler = link->data;
+
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (
                        store, &iter, DEST_NAME_COLUMN,
@@ -173,8 +173,6 @@ ask_destination_and_save (ESourceSelector *selector,
                        if (handler->options_widget)
                                gtk_widget_show (handler->options_widget);
                }
-
-               format_handlers = g_list_next (format_handlers);
        }
 
        g_signal_connect (
@@ -228,8 +226,7 @@ ask_destination_and_save (ESourceSelector *selector,
        }
 
        /* Free the handlers */
-       g_list_foreach (format_handlers, format_handlers_foreach_free, NULL);
-       g_list_free (format_handlers);
+       g_list_free_full (format_handlers, format_handlers_foreach_free);
 
        /* Now we can destroy it */
        gtk_widget_destroy (dialog);


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