[evolution-patches] [Exchange] Memory leak fix.



Hi,

Attached patch fixes some memory leaks in evolution-exchange modules.

Thanks,

V. Varadhan
? memory-leak-fix.patch
Index: calendar/e-cal-backend-exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange-calendar.c,v
retrieving revision 1.45
diff -u -p -r1.45 e-cal-backend-exchange-calendar.c
--- calendar/e-cal-backend-exchange-calendar.c	17 Aug 2005 07:17:49 -0000	1.45
+++ calendar/e-cal-backend-exchange-calendar.c	23 Aug 2005 15:38:53 -0000
@@ -200,8 +200,10 @@ add_ical (ECalBackendExchange *cbex, con
 	ical_body = g_strndup (start, end - start);
 	icalcomp = icalparser_parse_string (ical_body);
 	g_free (ical_body);
-	if (!icalcomp)
-		return FALSE;
+	if (!icalcomp) {
+		status = FALSE;
+		goto cleanup;
+	}
 
 	kind = icalcomponent_isa (icalcomp);
 	if (kind == ICAL_VEVENT_COMPONENT) {
@@ -212,17 +214,21 @@ add_ical (ECalBackendExchange *cbex, con
 		}
 		if (attachment_list) {
 			ecomp = e_cal_component_new ();
-			e_cal_component_set_icalcomponent (ecomp, icalcomponent_new_clone (icalcomp));
+			/* 
+			   We don't have to _clone_ the icalcomponent, since we are anyway getting
+			   a cloned icalcomponent back after setting the attachment_list.
+			   This fixes a memory leak.
+			*/
+			e_cal_component_set_icalcomponent (ecomp, icalcomp);
 			e_cal_component_set_attachment_list (ecomp, attachment_list);
 			icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (ecomp));
 			g_object_unref (ecomp);
 		}
 		status = add_vevent (cbex, href, lastmod, icalcomp);
-		icalcomponent_free (icalcomp);
-		return status;
+		goto cleanup;
 	} else if (kind != ICAL_VCALENDAR_COMPONENT) {
-		icalcomponent_free (icalcomp);
-		return FALSE;
+		status = FALSE;
+		goto cleanup;
 	}
 
 	add_timezones_from_comp (cbex, icalcomp);
@@ -247,9 +253,17 @@ add_ical (ECalBackendExchange *cbex, con
 		subcomp = icalcomponent_get_next_component (
 			icalcomp, ICAL_VEVENT_COMPONENT);
 	}
-	icalcomponent_free (icalcomp);
+	status = TRUE;
 
-	return TRUE;
+ cleanup:
+	if (icalcomp)
+		icalcomponent_free (icalcomp);
+	if (attachment_list) {
+		g_slist_foreach (attachment_list, g_free, NULL);
+		g_slist_free (attachment_list);
+		attachment_list = NULL;
+	}
+	return status;
 }
 
 static const char *event_properties[] = {
Index: calendar/e-cal-backend-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange.c,v
retrieving revision 1.40
diff -u -p -r1.40 e-cal-backend-exchange.c
--- calendar/e-cal-backend-exchange.c	22 Aug 2005 14:22:01 -0000	1.40
+++ calendar/e-cal-backend-exchange.c	23 Aug 2005 15:38:54 -0000
@@ -1397,7 +1397,7 @@ get_attachment (ECalBackendExchange *cbe
 				attach_file_url = save_attach_file (attach_file, attach_data, stream_mem->buffer->len);
 				g_free (attach_file);
 				d(printf ("attach file name : %s\n", attach_file_url));
-				list = g_slist_append (list, g_strdup (attach_file_url));
+				list = g_slist_append (list, attach_file_url);
 
 				camel_object_unref (stream);
 			}
@@ -1534,6 +1534,9 @@ build_msg ( ECalBackendExchange *cbex, E
 		return NULL;
 	}
 	e_cal_component_set_attachment_list (comp, new_attach_list);
+	g_slist_foreach (new_attach_list, g_free, NULL);
+	g_slist_free (new_attach_list);
+	new_attach_list = NULL;
 
 	camel_medium_set_content_object (CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER (multipart));
 	camel_object_unref (multipart);


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