Index: calendar/ChangeLog
===================================================================
--- calendar/ChangeLog	(revision 8050)
+++ calendar/ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2007-09-11  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #475781
+
+	* libecal/e-cal-component.c: (e_cal_component_free_datetime):
+	* backends/groupwise/e-cal-backend-groupwise-utils.c:
+	(set_properties_from_cal_component), (e_gw_item_to_cal_component):
+	* libecal/e-cal.c: (add_instance):
+	Fix memory leaks around ECalComponentDateTime.
+
 2007-09-10  Chenthill Palanisamy  <pchenthill@novell.com>
 
 	** Fix for bug #426421
Index: calendar/backends/groupwise/e-cal-backend-groupwise-utils.c
===================================================================
--- calendar/backends/groupwise/e-cal-backend-groupwise-utils.c	(revision 8050)
+++ calendar/backends/groupwise/e-cal-backend-groupwise-utils.c	(working copy)
@@ -533,6 +533,7 @@
 	GSList *slist, *sl;
 	icaltimezone *default_zone, *utc;
 	struct icaltimetype itt_utc;
+	gboolean dtstart_has_timezone;
 	
 	default_zone = e_cal_backend_groupwise_get_default_zone (cbgw);
 	utc = icaltimezone_get_utc_timezone ();
@@ -580,6 +581,7 @@
 			itt_utc = icaltime_convert_to_zone (*dt.value, utc);
 			e_gw_item_set_end_date (item, icaltime_as_ical_string (itt_utc));
 		}
+		e_cal_component_free_datetime (&dt);
 
 		break;
 
@@ -594,8 +596,9 @@
 			itt_utc = icaltime_convert_to_zone (*dt.value, utc);
 			e_gw_item_set_due_date (item, icaltime_as_ical_string (itt_utc));
 		}
-		
-			/* priority */
+		e_cal_component_free_datetime (&dt);
+
+		/* priority */
 		 priority = NULL;
 		 e_cal_component_get_priority (comp, &priority);
 		 if (priority && *priority) {
@@ -611,10 +614,12 @@
 			 e_cal_component_free_priority (priority);
 		 }
 	  
-			/* completed */
+		/* completed */
 		e_cal_component_get_completed (comp, &dt.value);
 		if (dt.value) {
 			e_gw_item_set_completed (item, TRUE);
+			e_cal_component_free_icaltimetype (dt.value);
+			dt.value = NULL;
 		} else
 			e_gw_item_set_completed (item, FALSE);
 
@@ -667,6 +672,7 @@
 		itt_utc = icaltime_convert_to_zone (*dt.value, utc);
 		e_gw_item_set_start_date (item, icaltime_as_ical_string (itt_utc));
 	} else if (e_gw_item_get_item_type (item) == E_GW_ITEM_TYPE_APPOINTMENT) {
+		e_cal_component_free_datetime (&dt);
 		/* appointments need the start date property */
 		g_object_unref (item);
 		return NULL;
@@ -676,6 +682,9 @@
 	if (dt.value && dt.value->is_date && e_gw_item_get_item_type (item) == E_GW_ITEM_TYPE_APPOINTMENT)
 		e_gw_item_set_is_allday_event (item, TRUE);
 	
+	dtstart_has_timezone = dt.tzid != NULL;
+	e_cal_component_free_datetime (&dt);
+	
 	/* creation date */
 	e_cal_component_get_created (comp, &dt.value);
 	if (dt.value) {
@@ -689,6 +698,8 @@
 		e_cal_component_get_dtstamp (comp, &itt);
 		e_gw_item_set_creation_date (item, icaltime_as_ical_string (itt));
 	}
+	e_cal_component_free_icaltimetype (dt.value);
+	dt.value = NULL;
 
 	/* classification */
 	e_cal_component_get_classification (comp, &classif);
@@ -717,7 +728,7 @@
 
 			GSList *recur_dates = NULL;
 			
-			if (dt.tzid)
+			if (dtstart_has_timezone)
 				e_cal_recur_generate_instances (comp, -1, -1,get_recur_instance, &recur_dates, resolve_tzid_cb, NULL, (icaltimezone *) default_zone);		
 			else 
 				e_cal_recur_generate_instances (comp, -1, -1,get_recur_instance, &recur_dates, resolve_tzid_cb, NULL, utc);		
@@ -1086,6 +1097,7 @@
 		recur_id->type = E_CAL_COMPONENT_RANGE_SINGLE;
 		recur_id->datetime = dt;
 		e_cal_component_set_recurid (comp, recur_id);
+		g_free (recur_id);
 	} else {
 
 		uid = e_gw_item_get_icalid (item);
Index: calendar/libecal/e-cal-component.c
===================================================================
--- calendar/libecal/e-cal-component.c	(revision 8050)
+++ calendar/libecal/e-cal-component.c	(working copy)
@@ -4736,6 +4736,9 @@
 
 	g_free (dt->value);
 	g_free ((char*)dt->tzid);
+
+	dt->value = NULL;
+	dt->tzid = NULL;
 }
 
 /**
Index: calendar/libecal/e-cal.c
===================================================================
--- calendar/libecal/e-cal.c	(revision 8050)
+++ calendar/libecal/e-cal.c	(working copy)
@@ -3325,7 +3325,6 @@
 	struct icaltimetype itt;
 	icalcomponent *icalcomp;
 	struct instances_info *instances_hold;
-	ECalComponentDateTime datetime;
 
 	instances_hold = data;
 	list = instances_hold->instances;
@@ -3333,7 +3332,6 @@
 	ci = g_new (struct comp_instance, 1);
 
 	icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
-	e_cal_component_get_dtstart (comp, &datetime);
 		
 	/* add the instance to the list */
 	ci->comp = e_cal_component_new ();
@@ -3343,7 +3341,10 @@
 	if (e_cal_util_component_has_recurrences (icalcomp)) {
 		if (!(icalcomponent_get_first_property (icalcomp, ICAL_RECURRENCEID_PROPERTY))) {
 			ECalComponentRange *range;
+			ECalComponentDateTime datetime;
 
+			e_cal_component_get_dtstart (comp, &datetime);
+
 			if (instances_hold->start_zone) 
 				itt = icaltime_from_timet_with_zone (start, datetime.value->is_date, instances_hold->start_zone);
 			else {
