Skip to content

Commit

Permalink
test/event-log.c: fully clear compare_content pointer
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ejoerns committed Oct 10, 2023
1 parent d97d334 commit 446ce59
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/event-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 446ce59

Please sign in to comment.