From 3b616f2e22891da33b11ff16477e63f660fa9351 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Thu, 23 Nov 2023 18:53:00 +0000 Subject: [PATCH] fixed memory leak in append_test_log() test --- test/append-test-log.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/append-test-log.c b/test/append-test-log.c index 3ce40f1..e9c798e 100644 --- a/test/append-test-log.c +++ b/test/append-test-log.c @@ -52,6 +52,7 @@ static void mf_chk_first(TestState *, void *); static void mf_chk_second(TestState *, void *); static void mf_chk_third(TestState*, void *); static void mk_log_data(LogData *); +static void clean_entry(TestLogEntry *); static void chk_ptr_chg( TestState *, @@ -128,6 +129,11 @@ missing_first(TestState *s) append_test_log(&ld.state, "baz"); test_context_with(s, "first_log", mf_chk_first, &ld); test_context_with(s, "last_log", chk_last, &ld); + TestLogEntry + *context = ld.second.next, + *warning = context->next; + clean_entry(context); + clean_entry(warning); } static void @@ -197,8 +203,7 @@ chk_last(TestState *s, void *ptr) chk_ptr_chg(s, 0, ld->state.last_log, &ld->second); chk_str_eq(s, "text", ld->state.last_log->text, "baz"); chk_ptr_eq(s, "next", ld->state.last_log->next, 0); - free(ld->state.last_log->text); - free(ld->state.last_log); + clean_entry(ld->state.last_log); } static void @@ -272,4 +277,11 @@ chk_ptr_chg_test( chk_ptr_ne(s, "not null", actual, 0); } +static void +clean_entry(TestLogEntry *e) +{ + free(e->text); + free(e); +} + //jl