From e8120c0665e9a231d97d8aacd6a897b979c45728 Mon Sep 17 00:00:00 2001 From: Allen Winter Date: Thu, 6 Oct 2022 09:43:51 -0400 Subject: fix a few resource leaks in the tests and examples as found by Coverity. --- examples/errors.c | 6 ++---- src/test/regression-component.c | 10 +++++----- src/test/regression.c | 13 ++++--------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/examples/errors.c b/examples/errors.c index f50c4c9d..25bccfdd 100644 --- a/examples/errors.c +++ b/examples/errors.c @@ -9,15 +9,13 @@ void program_errors() icalerror_clear_errno(); - (void)icalcomponent_new(ICAL_VEVENT_COMPONENT); + icalcomponent *comp = icalcomponent_new(ICAL_VEVENT_COMPONENT); if (icalerrno != ICAL_NO_ERROR){ - fprintf(stderr,"Horrible libical error: %s\n", icalerror_strerror(icalerrno)); - } - + icalcomponent_free(comp); } void component_errors(icalcomponent *comp) diff --git a/src/test/regression-component.c b/src/test/regression-component.c index 463e6bcb..2df42abc 100644 --- a/src/test/regression-component.c +++ b/src/test/regression-component.c @@ -282,11 +282,11 @@ void create_new_component_with_va_args() (void *)0), (void *)0); - ok("creating a complex vcalendar", (calendar != NULL)); if (VERBOSE && calendar) printf("%s\n", icalcomponent_as_ical_string(calendar)); icalcomponent_free(calendar); + ok("creating a complex vcalendar", (calendar != NULL)); } static void print_span(int c, struct icaltime_span span) @@ -342,13 +342,13 @@ void test_icalcomponent_get_span() (void *)0); span = icalcomponent_get_span(c); + icalcomponent_free(c); if (VERBOSE) print_span(tnum++, span); #if ADD_TESTS_BROKEN_BUILTIN_TZDATA int_is("America/Los_Angeles", span.start, 973350000); #endif - icalcomponent_free(c); /** test 2 * We specify times as floating, the returned span is in UTC @@ -381,13 +381,13 @@ void test_icalcomponent_get_span() (void *)0); span = icalcomponent_get_span(c); + icalcomponent_free(c); if (VERBOSE) print_span(tnum++, span); #if ADD_TESTS_BROKEN_BUILTIN_TZDATA int_is("America/New_York", span.start, 973360800); #endif - icalcomponent_free(c); /** test 4 * We specify times in two different timezones, the returned span @@ -404,13 +404,13 @@ void test_icalcomponent_get_span() (void *)0); span = icalcomponent_get_span(c); + icalcomponent_free(c); if (VERBOSE) print_span(tnum++, span); #if ADD_TESTS_BROKEN_BUILTIN_TZDATA int_is("America/New_York", span.start, 973360800); #endif - icalcomponent_free(c); /** test 5 * We specify start time in a timezone and a duration, the returned span @@ -427,13 +427,13 @@ void test_icalcomponent_get_span() (void *)0); span = icalcomponent_get_span(c); + icalcomponent_free(c); if (VERBOSE) print_span(tnum++, span); #if ADD_TESTS_BROKEN_BUILTIN_TZDATA int_is("America/Los_Angeles w/ duration", span.end, 973351800); #endif - icalcomponent_free(c); icalerror_set_errors_are_fatal(0); /** test 6 diff --git a/src/test/regression.c b/src/test/regression.c index 7c25b999..61b6f160 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -530,11 +530,10 @@ void test_components() (void *)0), icalproperty_vanew_xlicerror( "This is only a test", - icalparameter_new_xlicerrortype( - ICAL_XLICERRORTYPE_COMPONENTPARSEERROR), + icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR), (void *)0), - 0), - 0); + (void *)0), + (void *)0); if (VERBOSE) printf("Original Component:\n%s\n\n", icalcomponent_as_ical_string(c)); @@ -547,7 +546,6 @@ void test_components() printf("Child Component:\n%s\n\n", icalcomponent_as_ical_string(child)); str_is("test results of child component", icalcomponent_as_ical_string(child), good_child); - icalcomponent_free(c); estate = icalerror_get_errors_are_fatal(); @@ -1145,12 +1143,9 @@ void test_restriction() icalproperty_new_location("1CP Conference Room 4350"), (void *)0), (void *)0); valid = icalrestriction_check(comp); - - ok("icalrestriction_check() == 0", (valid == 0)); - (void)icalcomponent_as_ical_string(comp); - icalcomponent_free(comp); + ok("icalrestriction_check() == 0", (valid == 0)); } void test_calendar() -- cgit v1.2.1