aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libical/ChangeLog8
-rw-r--r--libical/src/libical/icalcomponent.c25
2 files changed, 27 insertions, 6 deletions
diff --git a/libical/ChangeLog b/libical/ChangeLog
index 984e40cfc7..ba2c98c222 100644
--- a/libical/ChangeLog
+++ b/libical/ChangeLog
@@ -1,3 +1,11 @@
+2001-09-10 Damon Chaplin <damon@ximian.com>
+
+ * src/libical/icalcomponent.c (icalcomponent_compare_vtimezones):
+ strdup the result of the first call to ical_component_as_ical_string()
+ since the second call may free it.
+ Also, don't free the results of ical_component_as_ical_string() since
+ it is a tmp buffer which is freed elsewhere.
+
2001-09-10 Federico Mena Quintero <federico@ximian.com>
Replace struct icalattachtype by an opaque icalattach that is
diff --git a/libical/src/libical/icalcomponent.c b/libical/src/libical/icalcomponent.c
index 660e739984..4829034f28 100644
--- a/libical/src/libical/icalcomponent.c
+++ b/libical/src/libical/icalcomponent.c
@@ -1637,7 +1637,7 @@ icalcomponent_handle_conflicting_vtimezones (icalcomponent *comp,
icalarray *tzids_to_rename)
{
struct icalcomponent_impl *impl = (struct icalcomponent_impl*)comp;
- int tzid_len, i, suffix, max_suffix = 0, num_elements;
+ int tzid_len, i, suffix, max_suffix = 1, num_elements;
char *tzid_copy, *new_tzid, suffix_buf[32];
/* Find the length of the TZID without any trailing digits. */
@@ -1861,7 +1861,7 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1,
{
icalproperty *prop1, *prop2;
const char *tzid1, *tzid2;
- char *tzid2_copy, *string1, *string2;
+ char *tzid2_copy, *string1, *string2, *string1_copy;
int cmp;
/* Get the TZID property of the first VTIMEZONE. */
@@ -1869,6 +1869,7 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1,
if (!prop1)
return -1;
+ /* This returns the pointer to the actual string in the property. */
tzid1 = icalproperty_get_tzid (prop1);
if (!tzid1)
return -1;
@@ -1878,6 +1879,7 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1,
if (!prop2)
return -1;
+ /* This returns the pointer to the actual string in the property. */
tzid2 = icalproperty_get_tzid (prop2);
if (!tzid2)
return -1;
@@ -1895,21 +1897,32 @@ static int icalcomponent_compare_vtimezones (icalcomponent *vtimezone1,
/* Now convert both VTIMEZONEs to strings and compare them. */
string1 = icalcomponent_as_ical_string (vtimezone1);
if (!string1) {
+ /* Try to reset the property. Though this may not work if we are low
+ on memory. */
+ icalproperty_set_tzid (prop2, tzid2_copy);
+ free (tzid2_copy);
+ return -1;
+ }
+
+ /* Copy the string, since it is in a temporary buffer which may get freed
+ during the next call. */
+ string1_copy = strdup (string1);
+ if (!string1_copy) {
+ icalproperty_set_tzid (prop2, tzid2_copy);
free (tzid2_copy);
return -1;
}
string2 = icalcomponent_as_ical_string (vtimezone2);
if (!string2) {
- free (string1);
+ icalproperty_set_tzid (prop2, tzid2_copy);
free (tzid2_copy);
return -1;
}
- cmp = strcmp (string1, string2);
+ cmp = strcmp (string1_copy, string2);
- free (string1);
- free (string2);
+ free (string1_copy);
/* Now reset the second TZID. */
icalproperty_set_tzid (prop2, tzid2_copy);