From: brarcher Date: Tue, 6 Nov 2012 04:11:37 +0000 (+0000) Subject: fix memory leaks X-Git-Tag: 0.10.0~516 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=258d5bb713789a9a2a09857f7d43f84500b549ff;p=check fix memory leaks This commit fixes several instances where elements are created but never free'd. Although these tests may be run in their own process space, and at the completion of the tests the memory will be free'd, it is still good practice to clean up. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@664 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/tests/check_check_fixture.c b/tests/check_check_fixture.c index cde6c0a..9642458 100644 --- a/tests/check_check_fixture.c +++ b/tests/check_check_fixture.c @@ -184,7 +184,7 @@ START_TEST(test_ch_setup_fail) ck_assert_msg(strcmp(strstat, "0%: Checks: 1, Failures: 1, Errors: 0") == 0, "SRunner stat string incorrect with checked setup failure"); - + free(strstat); trm = tr_str(srunner_failures(sr)[0]); /* Search for check_check_fixture.c:129 if this fails. */ @@ -196,6 +196,7 @@ START_TEST(test_ch_setup_fail) ck_abort_msg (errm); } + free(trm); } END_TEST @@ -298,7 +299,7 @@ START_TEST(test_ch_setup_sig) ck_assert_msg(strcmp(strstat, "0%: Checks: 1, Failures: 0, Errors: 1") == 0, "SRunner stat string incorrect with checked setup signal"); - + free(strstat); trm = tr_str(srunner_failures(sr)[0]); @@ -311,6 +312,7 @@ START_TEST(test_ch_setup_sig) ck_abort_msg (errm); } + free(trm); } END_TEST @@ -381,7 +383,7 @@ START_TEST(test_ch_teardown_fail) ck_assert_msg(strcmp(strstat, "0%: Checks: 1, Failures: 1, Errors: 0") == 0, "SRunner stat string incorrect with checked setup failure"); - + free(strstat); trm = tr_str(srunner_failures(sr)[0]); @@ -393,7 +395,7 @@ START_TEST(test_ch_teardown_fail) ck_abort_msg (errm); } - + free(trm); } END_TEST @@ -423,7 +425,7 @@ START_TEST(test_ch_teardown_sig) ck_assert_msg(strcmp(strstat, "0%: Checks: 1, Failures: 0, Errors: 1") == 0, "SRunner stat string incorrect with checked teardown signal"); - + free(strstat); trm = tr_str(srunner_failures(sr)[0]); @@ -436,7 +438,7 @@ START_TEST(test_ch_teardown_sig) ck_abort_msg (errm); } - + free(trm); } END_TEST @@ -484,6 +486,7 @@ START_TEST(test_ch_teardown_two_teardowns_fork) for (i = 0; i < nr_of_failures; i++) { char *trm = tr_str(tra[i]); if (strlen(errm) + strlen(trm) > 1022) { + free(trm); break; } strcat(errm, trm); diff --git a/tests/check_check_limit.c b/tests/check_check_limit.c index 156241c..3034c97 100644 --- a/tests/check_check_limit.c +++ b/tests/check_check_limit.c @@ -23,9 +23,11 @@ static void limit_teardown (void) START_TEST(test_summary) { - ck_assert_msg(strcmp(sr_stat_str(sr), + char * string = sr_stat_str(sr); + ck_assert_msg(strcmp(string, "100%: Checks: 0, Failures: 0, Errors: 0") == 0, "Bad statistics string for empty suite"); + free(string); } END_TEST diff --git a/tests/check_check_log.c b/tests/check_check_log.c index ed601b1..4534a16 100644 --- a/tests/check_check_log.c +++ b/tests/check_check_log.c @@ -38,6 +38,8 @@ START_TEST(test_set_log) ck_assert_msg (srunner_has_log (sr), "SRunner not logging"); ck_assert_msg (strcmp(srunner_log_fname(sr), "test_log") == 0, "Bad file name returned"); + + srunner_free(sr); } END_TEST @@ -67,6 +69,8 @@ START_TEST(test_set_log_env) /* restore old environment */ ck_assert_msg(restore_env("CK_LOG_FILE_NAME", old_val) == 0, "Failed to restore environment variable"); + + srunner_free(sr); } END_TEST @@ -77,6 +81,8 @@ START_TEST(test_no_set_log) ck_assert_msg (!srunner_has_log (sr), "SRunner not logging"); ck_assert_msg (srunner_log_fname(sr) == NULL, "Bad file name returned"); + + srunner_free(sr); } END_TEST @@ -90,6 +96,8 @@ START_TEST(test_double_set_log) ck_assert_msg(strcmp(srunner_log_fname(sr), "test_log") == 0, "Log file is initialize only and shouldn't be changeable once set"); + + srunner_free(sr); } END_TEST @@ -104,6 +112,8 @@ START_TEST(test_set_xml) ck_assert_msg (srunner_has_xml (sr), "SRunner not logging XML"); ck_assert_msg (strcmp(srunner_xml_fname(sr), "test_log.xml") == 0, "Bad file name returned"); + + srunner_free(sr); } END_TEST @@ -133,6 +143,8 @@ START_TEST(test_set_xml_env) /* restore old environment */ ck_assert_msg(restore_env("CK_XML_LOG_FILE_NAME", old_val) == 0, "Failed to restore environment variable"); + + srunner_free(sr); } END_TEST @@ -143,6 +155,8 @@ START_TEST(test_no_set_xml) ck_assert_msg (!srunner_has_xml (sr), "SRunner not logging XML"); ck_assert_msg (srunner_xml_fname(sr) == NULL, "Bad file name returned"); + + srunner_free(sr); } END_TEST @@ -156,6 +170,8 @@ START_TEST(test_double_set_xml) ck_assert_msg(strcmp(srunner_xml_fname(sr), "test_log.xml") == 0, "XML Log file is initialize only and shouldn't be changeable once set"); + + srunner_free(sr); } END_TEST diff --git a/tests/check_check_log_internal.c b/tests/check_check_log_internal.c index d8de218..a7344a8 100644 --- a/tests/check_check_log_internal.c +++ b/tests/check_check_log_internal.c @@ -47,8 +47,6 @@ Suite *make_log_internal_suite(void) tc_core_subunit = tcase_create("Core SubUnit"); suite_add_tcase(s, tc_core_subunit); tcase_add_test(tc_core_subunit, test_init_logging_subunit); -#else - tcase_create("Core SubUnit"); #endif return s;