fixed memory leak in append_test_log() test

This commit is contained in:
jlamothe 2023-11-23 18:53:00 +00:00
parent daf189dc8d
commit 3b616f2e22

View File

@ -52,6 +52,7 @@ static void mf_chk_first(TestState *, void *);
static void mf_chk_second(TestState *, void *); static void mf_chk_second(TestState *, void *);
static void mf_chk_third(TestState*, void *); static void mf_chk_third(TestState*, void *);
static void mk_log_data(LogData *); static void mk_log_data(LogData *);
static void clean_entry(TestLogEntry *);
static void chk_ptr_chg( static void chk_ptr_chg(
TestState *, TestState *,
@ -128,6 +129,11 @@ missing_first(TestState *s)
append_test_log(&ld.state, "baz"); append_test_log(&ld.state, "baz");
test_context_with(s, "first_log", mf_chk_first, &ld); test_context_with(s, "first_log", mf_chk_first, &ld);
test_context_with(s, "last_log", chk_last, &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 static void
@ -197,8 +203,7 @@ chk_last(TestState *s, void *ptr)
chk_ptr_chg(s, 0, ld->state.last_log, &ld->second); chk_ptr_chg(s, 0, ld->state.last_log, &ld->second);
chk_str_eq(s, "text", ld->state.last_log->text, "baz"); chk_str_eq(s, "text", ld->state.last_log->text, "baz");
chk_ptr_eq(s, "next", ld->state.last_log->next, 0); chk_ptr_eq(s, "next", ld->state.last_log->next, 0);
free(ld->state.last_log->text); clean_entry(ld->state.last_log);
free(ld->state.last_log);
} }
static void static void
@ -272,4 +277,11 @@ chk_ptr_chg_test(
chk_ptr_ne(s, "not null", actual, 0); chk_ptr_ne(s, "not null", actual, 0);
} }
static void
clean_entry(TestLogEntry *e)
{
free(e->text);
free(e);
}
//jl //jl