[evolution-data-server/gnome-2-30] e_cal_new_from_uri/e_cal_open_default emits runtime warning



commit bf47a23ee4994597ca0a8757edd5ff0798435517
Author: Milan Crha <mcrha redhat com>
Date:   Thu May 6 19:44:34 2010 +0200

    e_cal_new_from_uri/e_cal_open_default emits runtime warning
    
    The warning is "e_source_get_uri () called on source with no absolute URI!"
    and it's caused by freeing the ESourceList before ECal creation.
    This change is fixing the issue.

 calendar/libecal/e-cal.c |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/calendar/libecal/e-cal.c b/calendar/libecal/e-cal.c
index d1dfdac..7de9052 100644
--- a/calendar/libecal/e-cal.c
+++ b/calendar/libecal/e-cal.c
@@ -879,23 +879,28 @@ e_cal_new (ESource *source, ECalSourceType type)
 
 /* for each known source calls check_func, which should return TRUE if the required
    source have been found. Function returns NULL or the source on which was returned
-   TRUE by the check_func. Non-NULL pointer should be unreffed by g_object_unref. */
+   TRUE by the check_func. Non-NULL pointer should be unreffed by g_object_unref.
+
+   'sources' is an output parameter and cannot be NULL. When returned non-NULL, then
+   should be freed with g_object_unref function. */
 static ESource *
-search_known_sources (ECalSourceType type, gboolean (*check_func)(ESource *source, gpointer user_data), gpointer user_data, GError **error)
+search_known_sources (ECalSourceType type, gboolean (*check_func)(ESource *source, gpointer user_data), gpointer user_data, ESourceList **sources, GError **error)
 {
-	ESourceList *sources;
 	ESource *res = NULL;
 	GSList *g;
 	GError *err = NULL;
 
+	g_return_val_if_fail (sources != NULL, NULL);
 	g_return_val_if_fail (check_func != NULL, NULL);
 
-	if (!e_cal_get_sources (&sources, type, &err)) {
+	*sources = NULL;
+
+	if (!e_cal_get_sources (sources, type, &err)) {
 		g_propagate_error (error, err);
 		return NULL;
 	}
 
-	for (g = e_source_list_peek_groups (sources); g; g = g->next) {
+	for (g = e_source_list_peek_groups (*sources); g; g = g->next) {
 		ESourceGroup *group = E_SOURCE_GROUP (g->data);
 		GSList *s;
 
@@ -912,8 +917,6 @@ search_known_sources (ECalSourceType type, gboolean (*check_func)(ESource *sourc
 			break;
 	}
 
-	g_object_unref (sources);
-
 	return res;
 }
 
@@ -944,16 +947,19 @@ check_uri (ESource *source, gpointer uri)
 ECal *
 e_cal_new_from_uri (const gchar *uri, ECalSourceType type)
 {
+	ESourceList *sources = NULL;
 	ESource *source;
 	ECal *cal;
 
-	source = search_known_sources (type, check_uri, (gpointer) uri, NULL);
+	source = search_known_sources (type, check_uri, (gpointer) uri, &sources, NULL);
 	if (!source)
 		source = e_source_new_with_absolute_uri ("", uri);
 
 	cal = e_cal_new (source, type);
 
 	g_object_unref (source);
+	if (sources)
+		g_object_unref (sources);
 
 	return cal;
 }
@@ -4057,6 +4063,7 @@ check_default (ESource *source, gpointer data)
 gboolean
 e_cal_open_default (ECal **ecal, ECalSourceType type, ECalAuthFunc func, gpointer data, GError **error)
 {
+	ESourceList *sources = NULL;
 	GError *err = NULL;
 	ESource *default_source;
 	gboolean res = TRUE;
@@ -4064,9 +4071,11 @@ e_cal_open_default (ECal **ecal, ECalSourceType type, ECalAuthFunc func, gpointe
 	e_return_error_if_fail (ecal != NULL, E_CALENDAR_STATUS_INVALID_ARG);
 	*ecal = NULL;
 
-	default_source = search_known_sources (type, check_default, NULL, &err);
+	default_source = search_known_sources (type, check_default, NULL, &sources, &err);
 
 	if (err) {
+		if (sources)
+			g_object_unref (sources);
 		g_propagate_error (error, err);
 		return FALSE;
 	}
@@ -4105,6 +4114,9 @@ e_cal_open_default (ECal **ecal, ECalSourceType type, ECalAuthFunc func, gpointe
 		*ecal = NULL;
 	}
 
+	if (sources)
+		g_object_unref (sources);
+
 	return res;
 }
 



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