diff options
author | Damon Chaplin <damon@ximian.com> | 2001-09-11 07:07:51 +0800 |
---|---|---|
committer | Damon Chaplin <damon@src.gnome.org> | 2001-09-11 07:07:51 +0800 |
commit | e0beab13257c680c2772e842c82cf328f2ce4422 (patch) | |
tree | 217f79b4ad1f16a35135a4d9a9bce8dec5e58c92 | |
parent | 7eca7e459091e7f4fcea9223dff71fd179305cb5 (diff) | |
download | gsoc2013-evolution-e0beab13257c680c2772e842c82cf328f2ce4422.tar.gz gsoc2013-evolution-e0beab13257c680c2772e842c82cf328f2ce4422.tar.zst gsoc2013-evolution-e0beab13257c680c2772e842c82cf328f2ce4422.zip |
strdup the result of the first call to ical_component_as_ical_string()
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.
svn path=/trunk/; revision=12750
-rw-r--r-- | libical/ChangeLog | 8 | ||||
-rw-r--r-- | libical/src/libical/icalcomponent.c | 25 |
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); |