From 7e07badcd01e7d30933baa500a43b9cad7aa0205 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 16 Mar 2012 13:52:30 -0500 Subject: plug a string leak when updating appointments --- src/datetime-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index a782d80..4df2194 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -828,6 +828,7 @@ update_appointment_menu_items (gpointer user_data) apt_output = SETTINGS_TIME_24_HOUR; } } + g_free (time_format_str); GVariantBuilder markeddays; g_variant_builder_init (&markeddays, G_VARIANT_TYPE ("ai")); -- cgit v1.2.3 From f281d28db0ae9985f0b0f05d90d8210b2651fd24 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 16 Mar 2012 13:53:17 -0500 Subject: minor: remove unnecessary nesting --- src/datetime-service.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 4df2194..9c18d9b 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -821,12 +821,10 @@ update_appointment_menu_items (gpointer user_data) apt_output = SETTINGS_TIME_12_HOUR; } else if (g_strcmp0(time_format_str, "24-hour") == 0) { apt_output = SETTINGS_TIME_24_HOUR; + } else if (is_locale_12h()) { + apt_output = SETTINGS_TIME_12_HOUR; } else { - if (is_locale_12h()) { - apt_output = SETTINGS_TIME_12_HOUR; - } else { - apt_output = SETTINGS_TIME_24_HOUR; - } + apt_output = SETTINGS_TIME_24_HOUR; } g_free (time_format_str); -- cgit v1.2.3 From 2b461cbadb7d48c22625a5b8435dc0ea8314f948 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 18 Mar 2012 09:27:04 -0500 Subject: leak: fix GError leaks --- src/datetime-service.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 9c18d9b..7668689 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -719,6 +719,7 @@ update_appointment_menu_items (gpointer user_data) if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) { g_debug("Failed to get ecal sources\n"); + g_clear_error (&gerror); return FALSE; } @@ -1217,6 +1218,7 @@ geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, { if (error != NULL) { g_warning("Unable to get Geoclue address: %s", error->message); + g_clear_error (&error); return; } @@ -1278,6 +1280,7 @@ geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GErr { if (error != NULL) { g_warning("Unable to create GeoClue address: %s", error->message); + g_clear_error (&error); return; } @@ -1304,6 +1307,7 @@ geo_req_set (GeoclueMasterClient * master, GError * error, gpointer user_data) { if (error != NULL) { g_warning("Unable to set Geoclue requirements: %s", error->message); + g_clear_error (&error); } return; } @@ -1366,6 +1370,7 @@ geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * if (error != NULL) { g_warning("Unable to get a GeoClue client! '%s' Geolocation based timezone support will not be available.", error->message); + g_clear_error (&error); return; } -- cgit v1.2.3 From 54b21fbdf26c6b55dfc353238696fd4ada1609f7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 18 Mar 2012 09:29:08 -0500 Subject: minor: use g_clear_error() instead of g_error_free() --- src/datetime-service.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 7668689..ecf2807 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -273,7 +273,7 @@ quick_set_tz_cb (GObject *object, GAsyncResult *res, gpointer data) if (error != NULL) { g_warning("Could not set timezone for SettingsDaemon: %s", error->message); - g_error_free(error); + g_clear_error (&error); return; } @@ -289,7 +289,7 @@ quick_set_tz_proxy_cb (GObject *object, GAsyncResult *res, gpointer zone) if (error != NULL) { g_warning("Could not grab DBus proxy for SettingsDaemon: %s", error->message); - g_error_free(error); + g_clear_error (&error); g_free (zone); return; } @@ -363,7 +363,7 @@ execute_command (const gchar * command) g_debug("Issuing command '%s'", command); if (!g_spawn_command_line_async(command, &error)) { g_warning("Unable to start %s: %s", (char *)command, error->message); - g_error_free(error); + g_clear_error (&error); } } @@ -737,8 +737,7 @@ update_appointment_menu_items (gpointer user_data) GSList *cal_list = gconf_client_get_list(gconf, "/apps/evolution/calendar/display/selected_calendars", GCONF_VALUE_STRING, &gerror); if (gerror) { g_debug("Failed to get evolution preference for enabled calendars"); - g_error_free(gerror); - gerror = NULL; + g_clear_error (&gerror); cal_list = NULL; } @@ -760,16 +759,14 @@ update_appointment_menu_items (gpointer user_data) } if (current_zone && !e_cal_set_default_timezone(ecal, current_zone, &gerror)) { g_debug("Failed to set ecal default timezone %s", gerror->message); - g_error_free(gerror); - gerror = NULL; + g_clear_error (&gerror); g_object_unref(ecal); continue; } if (!e_cal_open(ecal, FALSE, &gerror)) { g_debug("Failed to get ecal sources %s", gerror->message); - g_error_free(gerror); - gerror = NULL; + g_clear_error (&gerror); g_object_unref(ecal); continue; } @@ -1010,7 +1007,8 @@ update_appointment_menu_items (gpointer user_data) g_debug("Adding appointment: %p", item); } - if (gerror != NULL) g_error_free(gerror); + g_clear_error (&gerror); + for (l = sorted_comp_instances; l; l = l->next) { const struct comp_instance *ci = l->data; g_object_unref(ci->comp); @@ -1205,7 +1203,7 @@ system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) if (error != NULL) { g_warning("Could not grab DBus proxy for ConsoleKit: %s", error->message); - g_error_free(error); + g_clear_error (&error); return; } -- cgit v1.2.3 From 1523323751cba68b7db8a3c39c35882d34590efc Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 18 Mar 2012 09:31:27 -0500 Subject: leak: plug leaks related to use of gconf_client_get_list() --- src/datetime-service.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index ecf2807..5b92029 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -532,7 +532,7 @@ calendar_app_is_usable (void) GSList *accounts_list = gconf_client_get_list (gconf, "/apps/evolution/mail/accounts", GCONF_VALUE_STRING, NULL); const guint n = g_slist_length (accounts_list); g_debug ("found %u evolution accounts", n); - g_slist_free (accounts_list); + g_slist_free_full (accounts_list, g_free); return n > 0; } @@ -790,6 +790,8 @@ update_appointment_menu_items (gpointer user_data) g_object_unref(ecal); } } + g_slist_free_full (cal_list, g_free); + g_debug("Number of ECalComponents returned: %d", g_list_length(comp_instances)); GList *sorted_comp_instances = g_list_sort(comp_instances, compare_comp_instances); comp_instances = NULL; -- cgit v1.2.3 From 69995999c5c5313ca357aab86eb59d1c3edd3b05 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 18 Mar 2012 09:34:01 -0500 Subject: don't subtract one time_t from another --- src/datetime-service.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 5b92029..b565f21 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -613,15 +613,15 @@ auth_func (ECal *ecal, } static gint -compare_comp_instances (gconstpointer a, - gconstpointer b) +compare_comp_instances (gconstpointer ga, gconstpointer gb) { - const struct comp_instance *ci_a = a; - const struct comp_instance *ci_b = b; - time_t d = ci_a->start - ci_b->start; - if (d < 0) return -1; - else if (d > 0) return 1; - return 0; + const struct comp_instance * a = ga; + const struct comp_instance * b = gb; + + /* sort by start time */ + if (a->start < b->start) return -1; + if (a->start > b->start) return 1; + return 0; } static gboolean -- cgit v1.2.3 From 881607dfdbe95f1e4759033d87ab064010dd8e44 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 18 Mar 2012 09:49:23 -0500 Subject: leak: fix the comp_instance struct leaks allocated in populate_appointment_instances() from update_appointment_menu_items(). The list was freed, but not the structs pointed to by the list. --- src/datetime-service.c | 63 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index b565f21..e00ff86 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -624,11 +624,31 @@ compare_comp_instances (gconstpointer ga, gconstpointer gb) return 0; } +static struct comp_instance* +comp_instance_new (ECalComponent * comp, time_t start, time_t end, ESource * source) +{ + g_object_ref(comp); + g_debug("Using times start %s, end %s", ctime(&start), ctime(&end)); + + struct comp_instance *ci = g_new (struct comp_instance, 1); + ci->comp = comp; + ci->source = source; + ci->start = start; + ci->end = end; + return ci; +} +static void +comp_instance_free (struct comp_instance* ci) +{ + g_object_unref (ci->comp); + g_free (ci); +} + static gboolean -populate_appointment_instances (ECalComponent *comp, - time_t instance_start, - time_t instance_end, - gpointer data) +populate_appointment_instances (ECalComponent * comp, + time_t start, + time_t end, + gpointer data) { g_debug("Appending item %p", comp); @@ -638,20 +658,9 @@ populate_appointment_instances (ECalComponent *comp, icalproperty_status status; e_cal_component_get_status (comp, &status); if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE; - - g_object_ref(comp); - struct comp_instance *ci; - ci = g_new (struct comp_instance, 1); - - g_debug("Using times start %s, end %s", ctime(&instance_start), ctime(&instance_end)); - - ci->comp = comp; - ci->source = E_SOURCE(data); - ci->start = instance_start; - ci->end = instance_end; - - comp_instances = g_list_append(comp_instances, ci); + struct comp_instance *ci = comp_instance_new (comp, start, end, E_SOURCE(data)); + comp_instances = g_list_append (comp_instances, ci); return TRUE; } @@ -723,17 +732,10 @@ update_appointment_menu_items (gpointer user_data) return FALSE; } - // Free comp_instances if not NULL - if (comp_instances != NULL) { - g_debug("Freeing comp_instances: may be an overlap\n"); - for (l = comp_instances; l; l = l->next) { - const struct comp_instance *ci = l->data; - g_object_unref(ci->comp); - } - g_list_free(comp_instances); - comp_instances = NULL; + // clear any previous comp_instances + g_list_free_full (comp_instances, (GDestroyNotify)comp_instance_free); + comp_instances = NULL; - } GSList *cal_list = gconf_client_get_list(gconf, "/apps/evolution/calendar/display/selected_calendars", GCONF_VALUE_STRING, &gerror); if (gerror) { g_debug("Failed to get evolution preference for enabled calendars"); @@ -1011,11 +1013,8 @@ update_appointment_menu_items (gpointer user_data) g_clear_error (&gerror); - for (l = sorted_comp_instances; l; l = l->next) { - const struct comp_instance *ci = l->data; - g_object_unref(ci->comp); - } - g_list_free(sorted_comp_instances); + g_list_free_full (sorted_comp_instances, (GDestroyNotify)comp_instance_free); + sorted_comp_instances = NULL; GVariant * marks = g_variant_builder_end (&markeddays); dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARKS, marks); -- cgit v1.2.3 From c31a4b20e1029de61406a204a462d2e233b2e7e6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 18 Mar 2012 10:01:44 -0500 Subject: minor: fix inefficient GSList walking -- only walk a GSList once instead of twice per node --- src/datetime-service.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index e00ff86..7d4a9f2 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -772,23 +772,17 @@ update_appointment_menu_items (gpointer user_data) g_object_unref(ecal); continue; } + const gchar *ecal_uid = e_source_peek_uid(source); - gboolean match = FALSE; g_debug("Checking ecal_uid is enabled: %s", ecal_uid); - for (i = 0; i Date: Sun, 18 Mar 2012 10:07:04 -0500 Subject: leak: fix GdkPixbuf leak when setting up appointments --- src/datetime-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 7d4a9f2..e628ef3 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -996,6 +996,7 @@ update_appointment_menu_items (gpointer user_data) } dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf); + g_clear_object (&pixbuf); } else { g_debug("Creating pixbuf from surface failed"); } -- cgit v1.2.3 From 763210baf2aeb40d3dc39399fd8787d01fad7196 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 18 Mar 2012 10:46:34 -0500 Subject: leak: fix ESourceList leak in update_appointment_menu_items() --- src/datetime-service.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index e628ef3..8aa01c0 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -1013,6 +1013,8 @@ update_appointment_menu_items (gpointer user_data) GVariant * marks = g_variant_builder_end (&markeddays); dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARKS, marks); + + g_clear_object (&sources); updating_appointments = FALSE; g_debug("End of objects"); -- cgit v1.2.3 From bee48b668c25011791cc67e5da9e1b0d8f60f549 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 21 Mar 2012 10:50:27 -0500 Subject: 0.3.92 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f033f41..6377b9a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_INIT([indicator-datetime], - [0.3.91], + [0.3.92], [http://bugs.launchpad.net/indicator-datetime], [indicator-datetime], [http://launchpad.net/indicator-datetime]) -- cgit v1.2.3