Avoid double free on iCal import errors

Set pointers to NULL after calling free() to prevent double free on
cleanup.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lukas Fleischer 2020-11-07 19:35:43 -05:00
parent 97df01b534
commit e1b5580bdf

View File

@ -1398,8 +1398,10 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
goto skip; goto skip;
} }
vevent.start = ical_datetime2time_t(p, tzid, vevent_type); vevent.start = ical_datetime2time_t(p, tzid, vevent_type);
if (tzid) if (tzid) {
mem_free(tzid); mem_free(tzid);
tzid = NULL;
}
if (!vevent.start) { if (!vevent.start) {
ical_log(log, ICAL_VEVENT, ITEMLINE, ical_log(log, ICAL_VEVENT, ITEMLINE,
_("invalid or malformed event " _("invalid or malformed event "
@ -1422,8 +1424,10 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
goto skip; goto skip;
} }
vevent.end = ical_datetime2time_t(p, tzid, vevent_type); vevent.end = ical_datetime2time_t(p, tzid, vevent_type);
if (tzid) if (tzid) {
mem_free(tzid); mem_free(tzid);
tzid = NULL;
}
if (!vevent.end) { if (!vevent.end) {
ical_log(log, ICAL_VEVENT, ITEMLINE, ical_log(log, ICAL_VEVENT, ITEMLINE,
_("malformed event end time.")); _("malformed event end time."));
@ -1506,6 +1510,7 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
if (vevent.desc) { if (vevent.desc) {
string_catf(&s, "%s", vevent.desc); string_catf(&s, "%s", vevent.desc);
mem_free(vevent.desc); mem_free(vevent.desc);
vevent.desc = NULL;
} }
if (separator) if (separator)
string_catf(&s, SEPARATOR); string_catf(&s, SEPARATOR);
@ -1513,16 +1518,19 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents,
string_catf(&s, _("Location: %s"), string_catf(&s, _("Location: %s"),
vevent.loc); vevent.loc);
mem_free(vevent.loc); mem_free(vevent.loc);
vevent.loc = NULL;
} }
if (vevent.comm) { if (vevent.comm) {
string_catf(&s, _("Comment: %s"), string_catf(&s, _("Comment: %s"),
vevent.comm); vevent.comm);
mem_free(vevent.comm); mem_free(vevent.comm);
vevent.comm = NULL;
} }
if (vevent.imp) { if (vevent.imp) {
string_catf(&s, ("Import: %s\n"), string_catf(&s, ("Import: %s\n"),
vevent.imp); vevent.imp);
mem_free(vevent.imp); mem_free(vevent.imp);
vevent.imp = NULL;
} }
vevent.note = generate_note(string_buf(&s)); vevent.note = generate_note(string_buf(&s));
mem_free(s.buf); mem_free(s.buf);
@ -1734,6 +1742,7 @@ ical_read_todo(FILE * fdi, FILE * log, unsigned *notodos, unsigned *noskipped,
if (vtodo.desc) { if (vtodo.desc) {
string_catf(&s, "%s", vtodo.desc); string_catf(&s, "%s", vtodo.desc);
mem_free(vtodo.desc); mem_free(vtodo.desc);
vtodo.desc = NULL;
} }
if (separator) if (separator)
string_catf(&s, SEPARATOR); string_catf(&s, SEPARATOR);
@ -1741,11 +1750,13 @@ ical_read_todo(FILE * fdi, FILE * log, unsigned *notodos, unsigned *noskipped,
string_catf(&s, _("Location: %s"), string_catf(&s, _("Location: %s"),
vtodo.loc); vtodo.loc);
mem_free(vtodo.loc); mem_free(vtodo.loc);
vtodo.loc = NULL;
} }
if (vtodo.comm) { if (vtodo.comm) {
string_catf(&s, _("Comment: %s"), string_catf(&s, _("Comment: %s"),
vtodo.comm); vtodo.comm);
mem_free(vtodo.comm); mem_free(vtodo.comm);
vtodo.comm = NULL;
} }
vtodo.note = generate_note(string_buf(&s)); vtodo.note = generate_note(string_buf(&s));
mem_free(s.buf); mem_free(s.buf);