[evolution/webkit] Add a bit more error checking and do not leak icalcomponent-s



commit 60a728e51179e9d12828c5f02721f2688cbe1b46
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 29 23:08:37 2011 +0200

    Add a bit more error checking and do not leak icalcomponent-s

 calendar/gui/comp-util.c                    |   11 ++++++++++-
 calendar/gui/e-calendar-selector.c          |    8 +++++---
 calendar/gui/e-calendar-view.c              |    2 ++
 calendar/gui/e-memo-list-selector.c         |    8 +++++---
 calendar/gui/e-task-list-selector.c         |    8 +++++---
 modules/calendar/e-cal-shell-backend.c      |   10 +++++++---
 modules/calendar/e-cal-shell-view-private.c |    3 +--
 modules/calendar/e-memo-shell-backend.c     |    6 +++++-
 modules/calendar/e-task-shell-backend.c     |   10 +++++++---
 9 files changed, 47 insertions(+), 19 deletions(-)
---
diff --git a/calendar/gui/comp-util.c b/calendar/gui/comp-util.c
index a6095d0..d44914f 100644
--- a/calendar/gui/comp-util.c
+++ b/calendar/gui/comp-util.c
@@ -722,7 +722,12 @@ comp_util_sanitize_recurrence_master (ECalComponent *comp,
 	}
 
 	master = e_cal_component_new ();
-	e_cal_component_set_icalcomponent (master, icalcomp);
+	if (!e_cal_component_set_icalcomponent (master, icalcomp)) {
+		icalcomponent_free (icalcomp);
+		g_object_unref (master);
+		g_return_if_reached ();
+		return;
+	}
 
 	/* Compare recur id and start date */
 	e_cal_component_get_recurid (comp, &rid);
@@ -739,6 +744,10 @@ comp_util_sanitize_recurrence_master (ECalComponent *comp,
 
 		e_cal_component_get_dtend (comp, &edt);
 
+		g_return_if_fail (msdt.value != NULL);
+		g_return_if_fail (medt.value != NULL);
+		g_return_if_fail (edt.value != NULL);
+
 		sdt.value->year = msdt.value->year;
 		sdt.value->month = msdt.value->month;
 		sdt.value->day = msdt.value->day;
diff --git a/calendar/gui/e-calendar-selector.c b/calendar/gui/e-calendar-selector.c
index d31578c..1a70ebb 100644
--- a/calendar/gui/e-calendar-selector.c
+++ b/calendar/gui/e-calendar-selector.c
@@ -43,9 +43,11 @@ calendar_selector_update_single_object (ECalClient *client,
 
 	uid = (gchar *) icalcomponent_get_uid (icalcomp);
 
-	if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, NULL))
-		return e_cal_client_modify_object_sync (
-			client, icalcomp, CALOBJ_MOD_ALL, NULL, NULL);
+	if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, NULL)) {
+		icalcomponent_free (tmp_icalcomp);
+
+		return e_cal_client_modify_object_sync (client, icalcomp, CALOBJ_MOD_ALL, NULL, NULL);
+	}
 
 	uid = NULL;
 	if (!e_cal_client_create_object_sync (client, icalcomp, &uid, NULL, NULL))
diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c
index 32c5301..8f87026 100644
--- a/calendar/gui/e-calendar-view.c
+++ b/calendar/gui/e-calendar-view.c
@@ -2091,6 +2091,8 @@ e_calendar_view_get_icalcomponent_summary (ECalClient *client, icalcomponent *ic
 				summary = g_strdup_printf ("%s (%d)", summary ? summary : "", dtnow.year - dtstart.year);
 				*free_text = summary != NULL;
 			}
+
+			icalcomponent_free (item_icalcomp);
 		}
 	}
 
diff --git a/calendar/gui/e-memo-list-selector.c b/calendar/gui/e-memo-list-selector.c
index abc4bf9..cbcd002 100644
--- a/calendar/gui/e-memo-list-selector.c
+++ b/calendar/gui/e-memo-list-selector.c
@@ -45,9 +45,11 @@ memo_list_selector_update_single_object (ECalClient *client,
 
 	uid = (gchar *) icalcomponent_get_uid (icalcomp);
 
-	if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, NULL))
-		return e_cal_client_modify_object_sync (
-			client, icalcomp, CALOBJ_MOD_ALL, NULL, NULL);
+	if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, NULL)) {
+		icalcomponent_free (tmp_icalcomp);
+
+		return e_cal_client_modify_object_sync (client, icalcomp, CALOBJ_MOD_ALL, NULL, NULL);
+	}
 
 	if (!e_cal_client_create_object_sync (client, icalcomp, &uid, NULL, NULL))
 		return FALSE;
diff --git a/calendar/gui/e-task-list-selector.c b/calendar/gui/e-task-list-selector.c
index 9d1fb5c..ff4e187 100644
--- a/calendar/gui/e-task-list-selector.c
+++ b/calendar/gui/e-task-list-selector.c
@@ -45,9 +45,11 @@ task_list_selector_update_single_object (ECalClient *client,
 
 	uid = (gchar *) icalcomponent_get_uid (icalcomp);
 
-	if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, NULL))
-		return e_cal_client_modify_object_sync (
-			client, icalcomp, CALOBJ_MOD_ALL, NULL, NULL);
+	if (e_cal_client_get_object_sync (client, uid, NULL, &tmp_icalcomp, NULL, NULL)) {
+		icalcomponent_free (tmp_icalcomp);
+
+		return e_cal_client_modify_object_sync (client, icalcomp, CALOBJ_MOD_ALL, NULL, NULL);
+	}
 
 	if (!e_cal_client_create_object_sync (client, icalcomp, &uid, NULL, NULL))
 		return FALSE;
diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c
index 8d0c6ef..4b2692e 100644
--- a/modules/calendar/e-cal-shell-backend.c
+++ b/modules/calendar/e-cal-shell-backend.c
@@ -624,10 +624,14 @@ cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
 	}
 
 	comp = e_cal_component_new ();
-	e_cal_component_set_icalcomponent (comp, icalcomp);
+	if (!e_cal_component_set_icalcomponent (comp, icalcomp)) {
+		g_debug ("%s: Failed to set icalcomp to comp\n", G_STRFUNC);
+		icalcomponent_free (icalcomp);
+		icalcomp = NULL;
+	}
 
-	icalprop = icalcomponent_get_first_property (
-		icalcomp, ICAL_ATTENDEE_PROPERTY);
+	icalprop = icalcomp ? icalcomponent_get_first_property (
+		icalcomp, ICAL_ATTENDEE_PROPERTY) : NULL;
 	if (icalprop != NULL)
 		flags |= COMP_EDITOR_MEETING;
 
diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c
index d4cee1a..0ca3f34 100644
--- a/modules/calendar/e-cal-shell-view-private.c
+++ b/modules/calendar/e-cal-shell-view-private.c
@@ -871,8 +871,7 @@ e_cal_shell_view_transfer_item_to (ECalShellView *cal_shell_view,
 			if (success) {
 				/* Use master object when working
 				 * with a recurring event ... */
-				icalcomp_clone =
-					icalcomponent_new_clone (icalcomp);
+				icalcomp_clone = icalcomponent_new_clone (icalcomp);
 				icalcomponent_free (icalcomp);
 			} else {
 				/* ... or remove the recurrence ID ... */
diff --git a/modules/calendar/e-memo-shell-backend.c b/modules/calendar/e-memo-shell-backend.c
index 8d39843..2be7889 100644
--- a/modules/calendar/e-memo-shell-backend.c
+++ b/modules/calendar/e-memo-shell-backend.c
@@ -419,7 +419,11 @@ memo_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
 	}
 
 	comp = e_cal_component_new ();
-	e_cal_component_set_icalcomponent (comp, icalcomp);
+	if (!e_cal_component_set_icalcomponent (comp, icalcomp)) {
+		g_debug ("%s: Failed to set icalcomp to comp\n", G_STRFUNC);
+		icalcomponent_free (icalcomp);
+		icalcomp = NULL;
+	}
 
 	if (e_cal_component_has_organizer (comp))
 		flags |= COMP_EDITOR_IS_SHARED;
diff --git a/modules/calendar/e-task-shell-backend.c b/modules/calendar/e-task-shell-backend.c
index 768f46f..ebee924 100644
--- a/modules/calendar/e-task-shell-backend.c
+++ b/modules/calendar/e-task-shell-backend.c
@@ -419,10 +419,14 @@ task_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
 	}
 
 	comp = e_cal_component_new ();
-	e_cal_component_set_icalcomponent (comp, icalcomp);
+	if (!e_cal_component_set_icalcomponent (comp, icalcomp)) {
+		g_debug ("%s: Failed to set icalcomp to comp\n", G_STRFUNC);
+		icalcomponent_free (icalcomp);
+		icalcomp = NULL;
+	}
 
-	icalprop = icalcomponent_get_first_property (
-		icalcomp, ICAL_ATTENDEE_PROPERTY);
+	icalprop = icalcomp ? icalcomponent_get_first_property (
+		icalcomp, ICAL_ATTENDEE_PROPERTY) : NULL;
 	if (icalprop != NULL)
 		flags |= COMP_EDITOR_IS_ASSIGNED;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]