From 446ce5951e67908117758677d55052795866da81 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Tue, 10 Oct 2023 22:21:00 +0200 Subject: [PATCH] test/event-log.c: fully clear compare_content pointer coverity code scanning seems to be irritated by re-using freed compare_content without having fully cleared the pointer: >>> CID 1522445: (USE_AFTER_FREE) >>> Using freed pointer "compare_content". And for auto cleanup this is actually a problem, as detected by coverity, too: >>> CID 1522445: (USE_AFTER_FREE) >>> Calling "g_autoptr_cleanup_generic_gfree" frees pointer "compare_content" which has already been freed. Thus simply correctly free the pointer before reusing it. Signed-off-by: Enrico Joerns --- test/event-log.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/event-log.c b/test/event-log.c index 87ca938f7..c00118fc3 100644 --- a/test/event-log.c +++ b/test/event-log.c @@ -235,7 +235,7 @@ static void event_log_test_max_files_rotation(EventLogFixture *fixture, /* search string must be in .1 file */ g_assert_true(g_file_get_contents(rotatefile, &compare_content, NULL, NULL)); g_assert_cmpstr(rotate_content, ==, compare_content); - g_free(compare_content); + g_clear_pointer(&compare_content, g_free); /* file size was 0, message size is 128 bytes, will rotate on 3rd message */ logger->writer(logger, fields, G_N_ELEMENTS(fields)); @@ -244,12 +244,12 @@ static void event_log_test_max_files_rotation(EventLogFixture *fixture, /* search string must be in .2 file (but not in .1) */ g_assert_true(g_file_get_contents(rotatefile, &compare_content, NULL, NULL)); g_assert_cmpstr(rotate_content, !=, compare_content); - g_free(compare_content); + g_clear_pointer(&compare_content, g_free); g_free(rotatefile); rotatefile = g_build_filename(fixture->tmpdir, "testfile.log.2", NULL); g_assert_true(g_file_get_contents(rotatefile, &compare_content, NULL, NULL)); g_assert_cmpstr(rotate_content, ==, compare_content); - g_free(compare_content); + g_clear_pointer(&compare_content, g_free); /* file size was 128, message size is 128 bytes, will rotate on 2nd message */ logger->writer(logger, fields, G_N_ELEMENTS(fields)); @@ -262,7 +262,7 @@ static void event_log_test_max_files_rotation(EventLogFixture *fixture, /* .3 file must not be created and search string must not be in .2 */ g_assert_true(g_file_get_contents(rotatefile, &compare_content, NULL, NULL)); g_assert_cmpstr(rotate_content, !=, compare_content); - g_free(compare_content); + g_clear_pointer(&compare_content, g_free); g_free(rotatefile); rotatefile = g_build_filename(fixture->tmpdir, "testfile.log.3", NULL); g_assert_false(g_file_get_contents(rotatefile, &compare_content, NULL, NULL));