Index: plugins/save-calendar/csv-format.c
===================================================================
--- plugins/save-calendar/csv-format.c	(revision 34224)
+++ plugins/save-calendar/csv-format.c	(working copy)
@@ -466,18 +466,15 @@
 
 			e_cal_component_get_dtstart (comp, &temp_dt);
 			line = add_time_to_csv (line, temp_dt.value ? temp_dt.value : NULL, config);
-			if (temp_dt.value)
-				e_cal_component_free_datetime (&temp_dt);
+			e_cal_component_free_datetime (&temp_dt);
 
 			e_cal_component_get_dtend (comp, &temp_dt);
 			line = add_time_to_csv (line, temp_dt.value ? temp_dt.value : NULL, config);
-			if (temp_dt.value)
-				e_cal_component_free_datetime (&temp_dt);
+			e_cal_component_free_datetime (&temp_dt);
 
 			e_cal_component_get_due (comp, &temp_dt);
 			line = add_time_to_csv (line, temp_dt.value ? temp_dt.value : NULL, config);
-			if (temp_dt.value)
-				e_cal_component_free_datetime (&temp_dt);
+			e_cal_component_free_datetime (&temp_dt);
 
 			e_cal_component_get_percent (comp, &temp_int);
 			line = add_nummeric_to_csv (line, temp_int, config);
Index: plugins/save-calendar/rdf-format.c
===================================================================
--- plugins/save-calendar/rdf-format.c	(revision 34224)
+++ plugins/save-calendar/rdf-format.c	(working copy)
@@ -324,19 +324,16 @@
 				e_cal_component_free_text_list (temp_list);
 
 			e_cal_component_get_dtstart (comp, &temp_dt);
-			 add_time_to_rdf (node, "dtstart", temp_dt.value ? temp_dt.value : NULL);
-			if (temp_dt.value)
-				e_cal_component_free_datetime (&temp_dt);
+			add_time_to_rdf (node, "dtstart", temp_dt.value ? temp_dt.value : NULL);
+			e_cal_component_free_datetime (&temp_dt);
 
 			e_cal_component_get_dtend (comp, &temp_dt);
 			add_time_to_rdf (node, "dtend", temp_dt.value ? temp_dt.value : NULL);
-			if (temp_dt.value)
-				e_cal_component_free_datetime (&temp_dt);
+			e_cal_component_free_datetime (&temp_dt);
 
 			e_cal_component_get_due (comp, &temp_dt);
 			add_time_to_rdf (node, "due", temp_dt.value ? temp_dt.value : NULL);
-			if (temp_dt.value)
-				e_cal_component_free_datetime (&temp_dt);
+			e_cal_component_free_datetime (&temp_dt);
 
 			e_cal_component_get_percent (comp, &temp_int);
 			add_nummeric_to_rdf (node, "percentComplete", temp_int);
Index: plugins/save-calendar/ChangeLog
===================================================================
--- plugins/save-calendar/ChangeLog	(revision 34224)
+++ plugins/save-calendar/ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2007-09-11  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #475781
+
+	* csv-format.c: (do_save_calendar_csv):
+	* rdf-format.c: (do_save_calendar_rdf):
+	Fix memory leaks around ECalComponentDateTime.
+
 2007-06-07  Gilles Dartiguelongue  <dartigug@esiee.fr>
 
 	* rdf-format.c: (add_nummeric_to_rdf), (add_time_to_rdf),
Index: plugins/itip-formatter/ChangeLog
===================================================================
--- plugins/itip-formatter/ChangeLog	(revision 34224)
+++ plugins/itip-formatter/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2007-09-11  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #475781
+
+	* itip-formatter.c: (format_itip_object):
+	Fix memory leaks around ECalComponentDateTime.
+
 2007-09-07  Chenthill Palanisamy  <pchenthill@novell.com>
 
 	Fixes #273417
Index: plugins/itip-formatter/itip-formatter.c
===================================================================
--- plugins/itip-formatter/itip-formatter.c	(revision 34224)
+++ plugins/itip-formatter/itip-formatter.c	(working copy)
@@ -2006,16 +2006,16 @@
 	/* Set the recurrence id */
 	if (check_is_instance (icalcomp) && datetime.value) {
 		ECalComponentRange *recur_id;
+		struct icaltimetype icaltime = icaltime_convert_to_zone (*datetime.value, to_zone);
 
-		*datetime.value = icaltime_convert_to_zone (*datetime.value, to_zone);
-		datetime.tzid = icaltimezone_get_tzid (to_zone);
-
 		recur_id = g_new0 (ECalComponentRange, 1);
 		recur_id->type = E_CAL_COMPONENT_RANGE_SINGLE;
-		recur_id->datetime = datetime;
+		recur_id->datetime.value = &icaltime;
+		recur_id->datetime.tzid = icaltimezone_get_tzid (to_zone);
 		e_cal_component_set_recurid (pitip->comp, recur_id);
-	} else
-       		e_cal_component_free_datetime (&datetime);
+		g_free (recur_id); /* it's ok to call g_free here */
+	}
+	e_cal_component_free_datetime (&datetime);
 
 	e_cal_component_get_dtend (pitip->comp, &datetime);
 	pitip->end_time = 0;
Index: calendar/gui/dialogs/recurrence-page.c
===================================================================
--- calendar/gui/dialogs/recurrence-page.c	(revision 34224)
+++ calendar/gui/dialogs/recurrence-page.c	(working copy)
@@ -1521,6 +1521,8 @@
 				r->until.second = 0;
 				r->until.is_date = TRUE;
 				r->until.is_utc = FALSE;
+
+				e_cal_component_free_datetime (&dt);
 			}
 
 			priv->ending_date_tt = r->until;
@@ -1767,6 +1769,7 @@
 				e_cal_component_get_dtstart (comp, &dt);
 				priv->month_index = dt.value->day;
 				priv->month_num = MONTH_NUM_LAST;
+				e_cal_component_free_datetime (&dt);
 			} else {
 				priv->month_index = nth;
 				priv->month_num = MONTH_NUM_DAY;
Index: calendar/gui/dialogs/memo-page.c
===================================================================
--- calendar/gui/dialogs/memo-page.c	(revision 34224)
+++ calendar/gui/dialogs/memo-page.c	(working copy)
@@ -388,6 +388,7 @@
 				      start_tt->day);
 	} else if (!(page->flags & COMP_EDITOR_PAGE_NEW_ITEM))
 		e_date_edit_set_time (E_DATE_EDIT (priv->start_date), -1);
+	e_cal_component_free_datetime (&d);
 
 	/* Classification. */
 	e_cal_component_get_classification (comp, &cl);
Index: calendar/gui/e-day-view.c
===================================================================
--- calendar/gui/e-day-view.c	(revision 34224)
+++ calendar/gui/e-day-view.c	(working copy)
@@ -4907,23 +4907,31 @@
 	date.tzid = NULL;
 
 	if (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_LEFT_EDGE) {
-		e_cal_component_get_dtstart (comp, &date);
-		is_date = date.value->is_date;
+		ECalComponentDateTime ecdt;
+
+		e_cal_component_get_dtstart (comp, &ecdt);
+		is_date = ecdt.value && ecdt.value->is_date;
 		if (!is_date)
 			date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		dt = day_view->day_starts[day_view->resize_start_row];
 		*date.value = icaltime_from_timet_with_zone (dt, is_date,
 							     e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		e_cal_component_set_dtstart (comp, &date);
+		e_cal_component_free_datetime (&ecdt);
+		date.tzid = NULL; /* do not reuse it later */
 	} else {
-		e_cal_component_get_dtend (comp, &date);
-		is_date = date.value->is_date;
+		ECalComponentDateTime ecdt;
+
+		e_cal_component_get_dtend (comp, &ecdt);
+		is_date = ecdt.value && ecdt.value->is_date;
 		if (!is_date)
 			date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		dt = day_view->day_starts[day_view->resize_end_row + 1];
 		*date.value = icaltime_from_timet_with_zone (dt, is_date,
 							     e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		e_cal_component_set_dtend (comp, &date);
+		e_cal_component_free_datetime (&ecdt);
+		date.tzid = NULL; /* do not reuse it later */
 	}
 	
 	e_cal_component_commit_sequence (comp);
@@ -5147,23 +5155,31 @@
 	date.tzid = NULL;
 
 	if (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_LEFT_EDGE) {
-		e_cal_component_get_dtstart (comp, &date);
-		is_date = date.value->is_date;
+		ECalComponentDateTime ecdt;
+
+		e_cal_component_get_dtstart (comp, &ecdt);
+		is_date = ecdt.value && ecdt.value->is_date;
 		if (!is_date)
 			date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		dt = day_view->day_starts[day_view->resize_start_row];
 		*date.value = icaltime_from_timet_with_zone (dt, is_date,
 							     e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		e_cal_component_set_dtstart (comp, &date);
+		e_cal_component_free_datetime (&ecdt);
+		date.tzid = NULL; /* do not reuse it later */
 	} else {
+		ECalComponentDateTime ecdt;
+
 		e_cal_component_get_dtend (comp, &date);
-		is_date = date.value->is_date;
+		is_date = ecdt.value && ecdt.value->is_date;
 		if (!is_date)
 			date.tzid = icaltimezone_get_tzid (e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		dt = day_view->day_starts[day_view->resize_end_row + 1];
 		*date.value = icaltime_from_timet_with_zone (dt, is_date,
 							     e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 		e_cal_component_set_dtend (comp, &date);
+		e_cal_component_free_datetime (&ecdt);
+		date.tzid = NULL; /* do not reuse it later */
 	}
 	
 	e_cal_component_commit_sequence (comp);
@@ -7672,35 +7688,41 @@
 				}
 
 				if (mod == CALOBJ_MOD_THIS) {
-					ECalComponentDateTime dt;
+					ECalComponentDateTime olddt, dt;
 
-					e_cal_component_get_dtstart (comp, &dt);
-					if (dt.value->zone) {
+					e_cal_component_get_dtstart (comp, &olddt);
+					if (olddt.value->zone) {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_start,
-							dt.value->is_date,
-							dt.value->zone);
+							olddt.value->is_date,
+							olddt.value->zone);
 					} else {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_start,
-							dt.value->is_date,
+							olddt.value->is_date,
 							e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 					}
+					dt.tzid = olddt.tzid;
 					e_cal_component_set_dtstart (comp, &dt);
+					dt.tzid = NULL;
+					e_cal_component_free_datetime (&olddt);
 
-					e_cal_component_get_dtend (comp, &dt);
-					if (dt.value->zone) {
+					e_cal_component_get_dtend (comp, &olddt);
+					if (olddt.value->zone) {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_end,
-							dt.value->is_date,
-							dt.value->zone);
+							olddt.value->is_date,
+							olddt.value->zone);
 					} else {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_end,
-							dt.value->is_date,
+							olddt.value->is_date,
 							e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 					}
+					dt.tzid = olddt.tzid;
 					e_cal_component_set_dtend (comp, &dt);
+					dt.tzid = NULL;
+					e_cal_component_free_datetime (&olddt);
 
 					e_cal_component_set_rdate_list (comp, NULL);
 					e_cal_component_set_rrule_list (comp, NULL);
@@ -7829,35 +7851,41 @@
 				}
 
 				if (mod == CALOBJ_MOD_THIS) {
-					ECalComponentDateTime dt;
+					ECalComponentDateTime olddt, dt;
 
-					e_cal_component_get_dtstart (comp, &dt);
-					if (dt.value->zone) {
+					e_cal_component_get_dtstart (comp, &olddt);
+					if (olddt.value->zone) {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_start,
-							dt.value->is_date,
-							dt.value->zone);
+							olddt.value->is_date,
+							olddt.value->zone);
 					} else {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_start,
-							dt.value->is_date,
+							olddt.value->is_date,
 							e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 					}
+					dt.tzid = olddt.tzid;
 					e_cal_component_set_dtstart (comp, &dt);
+					dt.tzid = NULL;
+					e_cal_component_free_datetime (&olddt);
 
-					e_cal_component_get_dtend (comp, &dt);
-					if (dt.value->zone) {
+					e_cal_component_get_dtend (comp, &olddt);
+					if (olddt.value->zone) {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_end,
-							dt.value->is_date,
-							dt.value->zone);
+							olddt.value->is_date,
+							olddt.value->zone);
 					} else {
 						*dt.value = icaltime_from_timet_with_zone (
 							event->comp_data->instance_end,
-							dt.value->is_date,
+							olddt.value->is_date,
 							e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
 					}
+					dt.tzid = olddt.tzid;
 					e_cal_component_set_dtend (comp, &dt);
+					dt.tzid = NULL;
+					e_cal_component_free_datetime (&olddt);
 
 					e_cal_component_set_rdate_list (comp, NULL);
 					e_cal_component_set_rrule_list (comp, NULL);
Index: calendar/gui/itip-utils.c
===================================================================
--- calendar/gui/itip-utils.c	(revision 34224)
+++ calendar/gui/itip-utils.c	(working copy)
@@ -1111,6 +1111,7 @@
 			icaltimezone_convert_time (&r->until, from_zone, to_zone);
 			r->until.is_utc = TRUE;
 
+			e_cal_component_free_datetime (&dt);
 			e_cal_component_set_rrule_list (clone, rrule_list);
 			e_cal_component_abort_sequence (clone);
 		}
@@ -1516,7 +1517,7 @@
 			start = icaltime_as_timet_with_zone (*dtstart.value, start_zone);
 			time = g_strdup (ctime (&start));
 		}
-		
+		e_cal_component_free_datetime (&dtstart);
 	
 		body = g_string_new ("<br><br><hr><br><b>______ Original Appointment ______ </b><br><br><table>");
 
Index: calendar/gui/e-week-view.c
===================================================================
--- calendar/gui/e-week-view.c	(revision 34224)
+++ calendar/gui/e-week-view.c	(working copy)
@@ -3529,20 +3529,27 @@
 
 				if (mod == CALOBJ_MOD_THIS) {
 					ECalComponentDateTime dt;
+					struct icaltimetype tt;
+					char *tzid;
 
 					e_cal_component_get_dtstart (comp, &dt);
 					if (dt.value->zone) {
-						*dt.value = icaltime_from_timet_with_zone (
+						tt = icaltime_from_timet_with_zone (
 							event->comp_data->instance_start,
 							dt.value->is_date,
 							dt.value->zone);
 					} else {
-						*dt.value = icaltime_from_timet_with_zone (
+						tt = icaltime_from_timet_with_zone (
 							event->comp_data->instance_start,
 							dt.value->is_date,
 							e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
 					}
+					tzid = g_strdup (dt.tzid);
+					e_cal_component_free_datetime (&dt);
+					dt.value = &tt;
+					dt.tzid = tzid;
 					e_cal_component_set_dtstart (comp, &dt);
+					g_free (tzid);
 
 					e_cal_component_get_dtend (comp, &dt);
 					if (dt.value->zone) {
@@ -3556,7 +3563,12 @@
 							dt.value->is_date,
 							e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
 					}
+					tzid = g_strdup (dt.tzid);
+					e_cal_component_free_datetime (&dt);
+					dt.value = &tt;
+					dt.tzid = tzid;
 					e_cal_component_set_dtend (comp, &dt);
+					g_free (tzid);
 
 					e_cal_component_set_rdate_list (comp, NULL);
 					e_cal_component_set_rrule_list (comp, NULL);
Index: calendar/gui/e-calendar-view.c
===================================================================
--- calendar/gui/e-calendar-view.c	(revision 34224)
+++ calendar/gui/e-calendar-view.c	(working copy)
@@ -363,13 +363,16 @@
 	g_free (uid);
 
 	/* set the timezone properly */
-	dt.value = &itime;
 	e_cal_component_get_dtstart (comp, &dt);
 	dt.tzid = icaltimezone_get_tzid (default_zone);
 	e_cal_component_set_dtstart (comp, &dt);
+	e_cal_component_free_datetime (&dt);
+
 	e_cal_component_get_dtend (comp, &dt);
 	dt.tzid = icaltimezone_get_tzid (default_zone);
 	e_cal_component_set_dtend (comp, &dt);
+	e_cal_component_free_datetime (&dt);
+
 	e_cal_component_commit_sequence (comp);
 
 	/* FIXME Error handling */
@@ -2246,7 +2249,10 @@
 		
 	tmp1 = get_label(dtstart.value, zone, default_zone);
 	tmp = calculate_time (t_start, t_end);
-	
+
+	e_cal_component_free_datetime (&dtstart);
+	e_cal_component_free_datetime (&dtend);
+
 	/* To Translators: It will display "Time: ActualStartDateAndTime (DurationOfTheMeeting)"*/
 	tmp2 = g_strdup_printf(_("Time: %s %s"), tmp1, tmp);
 	hbox = gtk_hbox_new (FALSE, 0);
Index: calendar/gui/e-cal-component-preview.c
===================================================================
--- calendar/gui/e-cal-component-preview.c	(revision 34224)
+++ calendar/gui/e-cal-component-preview.c	(working copy)
@@ -199,9 +199,9 @@
 		gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>",
 					_("Start Date:"), str);
 
-		e_cal_component_free_datetime (&dt);
 		g_free (str);
 	}
+	e_cal_component_free_datetime (&dt);
 
 	/* write end date */
 	e_cal_component_get_dtend (comp, &dt);
@@ -210,9 +210,9 @@
 		gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>",
 					_("Start Date:"), str);
 
-		e_cal_component_free_datetime (&dt);
 		g_free (str);
 	}
+	e_cal_component_free_datetime (&dt);
 	
 	/* write Due Date */
 	e_cal_component_get_due (comp, &dt);
@@ -221,9 +221,9 @@
 		gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>",
 					_("Due Date:"), str);
 
-		e_cal_component_free_datetime (&dt);
 		g_free (str);
 	}
+	e_cal_component_free_datetime (&dt);
 	
 	/* write status */
 	gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Status:"));
Index: calendar/gui/e-cal-component-memo-preview.c
===================================================================
--- calendar/gui/e-cal-component-memo-preview.c	(revision 34224)
+++ calendar/gui/e-cal-component-memo-preview.c	(working copy)
@@ -211,9 +211,9 @@
 		gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>",
 					_("Start Date:"), str);
 
-		e_cal_component_free_datetime (&dt);
 		g_free (str);
 	}
+	e_cal_component_free_datetime (&dt);
 
 	/* write description and URL */
 	gtk_html_stream_printf (stream, "<TR><TD COLSPAN=\"2\"><HR></TD></TR>");
Index: calendar/gui/e-cal-model.c
===================================================================
--- calendar/gui/e-cal-model.c	(revision 34224)
+++ calendar/gui/e-cal-model.c	(working copy)
@@ -1309,6 +1309,7 @@
 	to_set.value = &time;
 	to_set.tzid = datetime.tzid; 
 	e_cal_component_set_dtstart (comp, &to_set);
+	e_cal_component_free_datetime (&datetime);
 	
 	/* set the right instance end date to component*/
 	e_cal_component_get_dtend (comp, &datetime);
@@ -1317,6 +1318,7 @@
 	to_set.value = &time;
 	to_set.tzid = datetime.tzid; 
 	e_cal_component_set_dtend (comp, &to_set);
+	e_cal_component_free_datetime (&datetime);
 
 	comp_data = g_new0 (ECalModelComponent, 1);
 	comp_data->client = g_object_ref (rdata->client);
Index: calendar/ChangeLog
===================================================================
--- calendar/ChangeLog	(revision 34224)
+++ calendar/ChangeLog	(working copy)
@@ -1,3 +1,21 @@
+2007-09-11  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #475781
+
+	* gui/dialogs/recurrence-page.c: (fill_ending_date),
+	(recurrence_page_fill_widgets):
+	* gui/dialogs/memo-page.c: (memo_page_fill_widgets):
+	* gui/e-day-view.c: 2*(e_day_view_finish_long_event_resize),
+	2*(e_day_view_on_editing_stopped):
+	* gui/itip-utils.c: (comp_compliant), (reply_to_calendar_comp):
+	* gui/e-week-view.c: (e_week_view_on_editing_stopped):
+	* gui/e-calendar-view.c: (e_calendar_view_add_event),
+	(e_calendar_view_get_tooltips):
+	* gui/e-cal-component-preview.c: (write_html):
+	* gui/e-cal-component-memo-preview.c: (write_html):
+	* gui/e-cal-model.c: (add_instance_cb):
+	Fix memory leaks around ECalComponentDateTime.
+
 2007-09-10  Suman Manjunath  <msuman@novell.com>
 
 	** Fix for bug #300284 (bnc)
