From ae2246b944b66b5fccf21e3008c2d63f38833b05 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 7 Apr 2007 03:24:19 +0000 Subject: Use a GString to construct the body contents and also fix several memory 2007-04-06 Matthew Barnes * gui/itip-utils.c (reply_to_calendar_comp): Use a GString to construct the body contents and also fix several memory leaks. (#408423) Based on a patch from Daniel Gryniewicz. svn path=/trunk/; revision=33397 --- calendar/ChangeLog | 6 ++++ calendar/gui/itip-utils.c | 73 ++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 03ac9e5ecf..3b0e590eb1 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,9 @@ +2007-04-06 Matthew Barnes + + * gui/itip-utils.c (reply_to_calendar_comp): + Use a GString to construct the body contents and also fix several + memory leaks. (#408423) Based on a patch from Daniel Gryniewicz. + 2007-04-06 Matthew Barnes * gui/memos-component.c (impl__get_userCreatableItems): diff --git a/calendar/gui/itip-utils.c b/calendar/gui/itip-utils.c index b8c5324369..10a598211e 100644 --- a/calendar/gui/itip-utils.c +++ b/calendar/gui/itip-utils.c @@ -1411,12 +1411,12 @@ reply_to_calendar_comp (ECalComponentItipMethod method, ECalComponent *send_comp if (e_cal_component_get_vtype (comp) == E_CAL_COMPONENT_EVENT){ - char *body = NULL; - char *orig_from = (char *) malloc (sizeof (char) * 100); + GString *body; + char *orig_from = NULL; char *description = NULL; - char *subject = (char *) malloc (sizeof (char) * 100); - char *location = (char *) malloc (sizeof (char) * 100); - char *time = (char *) malloc (sizeof (char) * 64); + char *subject = NULL; + const char *location = NULL; + char *time = NULL; char *html_description = NULL; GSList *text_list = NULL; ECalComponentOrganizer organizer; @@ -1448,11 +1448,9 @@ reply_to_calendar_comp (ECalComponentItipMethod method, ECalComponent *send_comp e_cal_component_get_organizer (comp, &organizer); if (organizer.value) orig_from = g_strdup (itip_strip_mailto (organizer.value)); - else - orig_from = ""; - e_cal_component_get_location (comp, (const char **)&location); + e_cal_component_get_location (comp, &location); if (!location) location = "Unspecified"; @@ -1469,46 +1467,43 @@ reply_to_calendar_comp (ECalComponentItipMethod method, ECalComponent *send_comp start_zone = calendar_config_get_icaltimezone (); start = icaltime_as_timet_with_zone (*dtstart.value, start_zone); - strcpy (time, ctime (&start)); + time = g_strdup (ctime (&start)); } - body = "



______ Original Appointment ______

"; + body = g_string_new ("



______ Original Appointment ______

"); - if (orig_from && *orig_from){ - char *part1 = (char *) malloc (sizeof (char) * 200); - sprintf (part1, "", orig_from); - body = g_strconcat (body, (gchar *)part1, NULL); - g_free (part1); - } + if (orig_from && *orig_from) + g_string_append_printf (body, + "" + "", orig_from); + g_free (orig_from); - if (subject){ - char *part2 = (char *) malloc (sizeof (char) * 100); - sprintf (part2, "", subject); - body = g_strconcat (body, (gchar *)part2, NULL); - g_free (part2); - } - - { - char *part3 = (char *) malloc (sizeof (char) * 100); - sprintf (part3, "", location); - body = g_strconcat (body, (gchar *)part3, NULL); - g_free (part3); - } + if (subject) + g_string_append_printf (body, + "" + "", subject); + g_free (subject); - if (time){ - char *part4 = (char *) malloc (sizeof (char) * 100); - sprintf (part4, "
From:%s
From:%s
Subject:%s
Location:%s
Subject:%s
Time:%s

", time); - body = g_strconcat (body, (gchar *)part4, NULL); - g_free (part4); - } + g_string_append_printf (body, + "Location" + ":%s", location); - html_description = html_new_lines_for (description); - body = g_strconcat (body, (gchar *)html_description, NULL); + if (time) + g_string_append_printf (body, + "Time" + ":%s", time); + g_free (time); + + g_string_append_printf (body, "
"); + html_description = html_new_lines_for (description); + g_string_append (body, html_description); g_free (html_description); - - GNOME_Evolution_Composer_setBody (composer_server, body, "text/html", &ev); + + GNOME_Evolution_Composer_setBody (composer_server, body->str, "text/html", &ev); + g_string_free (body, TRUE); + if (BONOBO_EX (&ev)) { g_warning ("Unable to set body text while sending iTip message"); goto cleanup; -- cgit v1.2.3