summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Wood <thomas.wood@intel.com>2010-07-16 13:53:34 +0100
committerThomas Wood <thomas.wood@intel.com>2010-07-16 13:53:34 +0100
commit20a5421543fe7830a48587fc97075550c6951b6b (patch)
treef145f490334adc900480b364ec9dea693d103b06
parent939fb9c16a4515afc21956eb2e519058c50427bc (diff)
downloadgnome-control-center-20a5421543fe7830a48587fc97075550c6951b6b.tar.gz
datetime: fix various memory leaks
- Add a function to free the timezone database - Use setenv rather than putenv - Add various missing free() calls
-rw-r--r--panels/datetime/cc-datetime-panel.c15
-rw-r--r--panels/datetime/cc-timezone-map.c5
-rw-r--r--panels/datetime/datetime.ui4
-rw-r--r--panels/datetime/tz.c26
-rw-r--r--panels/datetime/tz.h1
5 files changed, 37 insertions, 14 deletions
diff --git a/panels/datetime/cc-datetime-panel.c b/panels/datetime/cc-datetime-panel.c
index 8baf6a174..5cc74099b 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 926095401..318aa6b5b 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 bc386dfeb..73a4bcd09 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 2b4f3427f..80efa762b 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 885a5e691..e11263043 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);