[gnome-control-center] datetime: fix various memory leaks
- From: Thomas Wood <thos src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] datetime: fix various memory leaks
- Date: Fri, 16 Jul 2010 14:18:17 +0000 (UTC)
commit 20a5421543fe7830a48587fc97075550c6951b6b
Author: Thomas Wood <thomas wood intel com>
Date: Fri Jul 16 13:53:34 2010 +0100
datetime: fix various memory leaks
- Add a function to free the timezone database
- Use setenv rather than putenv
- Add various missing free() calls
panels/datetime/cc-datetime-panel.c | 15 ++++++++++-----
panels/datetime/cc-timezone-map.c | 5 ++++-
panels/datetime/datetime.ui | 4 ++--
panels/datetime/tz.c | 26 ++++++++++++++++++++------
panels/datetime/tz.h | 1 +
5 files changed, 37 insertions(+), 14 deletions(-)
---
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c
index 8baf6a1..5cc7409 100644
--- a/panels/datetime/cc-datetime-panel.c
+++ b/panels/datetime/cc-datetime-panel.c
@@ -327,7 +327,7 @@ get_regions (TzLocation *loc,
gtk_list_store_insert_with_values (data->city_store, NULL, 0,
0, split[1],
1, split[0],
- 2, loc,
+ 2, loc->zone,
-1);
g_strfreev (split);
@@ -389,6 +389,8 @@ load_regions_model (GtkListStore *regions, GtkListStore *cities)
GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (cities), 0,
GTK_SORT_ASCENDING);
+
+ tz_db_free (db);
}
static void
@@ -404,7 +406,7 @@ city_changed_cb (GtkComboBox *box,
{
static gboolean inside = FALSE;
GtkTreeIter iter;
- TzLocation *location;
+ gchar *zone;
/* prevent re-entry from location changed callback */
if (inside)
@@ -415,10 +417,11 @@ city_changed_cb (GtkComboBox *box,
if (gtk_combo_box_get_active_iter (box, &iter))
{
gtk_tree_model_get (gtk_combo_box_get_model (box), &iter,
- 2, &location, -1);
+ 2, &zone, -1);
+
+ cc_timezone_map_set_timezone (CC_TIMEZONE_MAP (self->priv->map), zone);
- cc_timezone_map_set_timezone (CC_TIMEZONE_MAP (self->priv->map),
- location->zone);
+ g_free (zone);
}
inside = FALSE;
@@ -471,6 +474,8 @@ cc_date_time_panel_init (CcDateTimePanel *self)
gtk_calendar_select_day (GTK_CALENDAR (widget), g_date_get_day (date));
gtk_calendar_select_month (GTK_CALENDAR (widget), g_date_get_month (date) -1,
g_date_get_year (date));
+ g_date_free (date);
+ date = NULL;
update_time (self);
diff --git a/panels/datetime/cc-timezone-map.c b/panels/datetime/cc-timezone-map.c
index 9260954..318aa6b 100644
--- a/panels/datetime/cc-timezone-map.c
+++ b/panels/datetime/cc-timezone-map.c
@@ -179,7 +179,7 @@ cc_timezone_map_finalize (GObject *object)
if (priv->tzdb)
{
- g_free (priv->tzdb);
+ tz_db_free (priv->tzdb);
priv->tzdb = NULL;
}
@@ -327,6 +327,9 @@ cc_timezone_map_expose_event (GtkWidget *widget,
file = g_strdup_printf (DATADIR "/timezone_%g.png",
priv->selected_offset);
orig_hilight = gdk_pixbuf_new_from_file (file, &err);
+ g_free (file);
+ file = NULL;
+
if (!orig_hilight)
{
g_warning ("Could not load hilight: %s",
diff --git a/panels/datetime/datetime.ui b/panels/datetime/datetime.ui
index bc386df..73a4bcd 100644
--- a/panels/datetime/datetime.ui
+++ b/panels/datetime/datetime.ui
@@ -278,8 +278,8 @@
<column type="gchararray"/>
<!-- column-name region -->
<column type="gchararray"/>
- <!-- column-name location -->
- <column type="gpointer"/>
+ <!-- column-name zone -->
+ <column type="gchararray"/>
</columns>
</object>
<object class="GtkTreeModelFilter" id="city-modelfilter">
diff --git a/panels/datetime/tz.c b/panels/datetime/tz.c
index 2b4f342..80efa76 100644
--- a/panels/datetime/tz.c
+++ b/panels/datetime/tz.c
@@ -128,6 +128,24 @@ tz_load_db (void)
return tz_db;
}
+static void
+tz_location_free (TzLocation *loc)
+{
+ g_free (loc->country);
+ g_free (loc->zone);
+ g_free (loc->comment);
+
+ g_free (loc);
+}
+
+void
+tz_db_free (TzDB *db)
+{
+ g_ptr_array_foreach (db->locations, tz_location_free, NULL);
+ g_ptr_array_free (db->locations, TRUE);
+ g_free (db);
+}
+
GPtrArray *
tz_get_locations (TzDB *db)
{
@@ -178,7 +196,6 @@ tz_location_get_utc_offset (TzLocation *loc)
gint
tz_location_set_locally (TzLocation *loc)
{
- gchar *str;
time_t curtime;
struct tm *curzone;
gboolean is_dst = FALSE;
@@ -191,8 +208,7 @@ tz_location_set_locally (TzLocation *loc)
curzone = localtime (&curtime);
is_dst = curzone->tm_isdst;
- str = g_strdup_printf ("TZ=%s", loc->zone);
- putenv (str);
+ setenv ("TZ", loc->zone, 1);
#if 0
curtime = time (NULL);
curzone = localtime (&curtime);
@@ -212,15 +228,13 @@ TzInfo *
tz_info_from_location (TzLocation *loc)
{
TzInfo *tzinfo;
- gchar *str;
time_t curtime;
struct tm *curzone;
g_return_val_if_fail (loc != NULL, NULL);
g_return_val_if_fail (loc->zone != NULL, NULL);
- str = g_strdup_printf ("TZ=%s", loc->zone);
- putenv (str);
+ setenv ("TZ", loc->zone, 1);
#if 0
tzset ();
diff --git a/panels/datetime/tz.h b/panels/datetime/tz.h
index 885a5e6..e112630 100644
--- a/panels/datetime/tz.h
+++ b/panels/datetime/tz.h
@@ -70,6 +70,7 @@ struct _TzInfo
TzDB *tz_load_db (void);
+void tz_db_free (TzDB *db);
GPtrArray *tz_get_locations (TzDB *db);
void tz_location_get_position (TzLocation *loc,
double *longitude, double *latitude);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]