warn to log instead of stderr

When the reindex function rebuilds the log because of a missing first_log value, it warns about a potential memory leak to the log itself.
This commit is contained in:
jlamothe 2023-11-21 23:26:32 +00:00
parent 00ffef2f0a
commit 6539b87ea9
2 changed files with 37 additions and 2 deletions

View File

@ -389,7 +389,8 @@ reindex(TestState *s)
else if (s->last_log) // we have a last log but no first?
{
s->first_log = s->last_log;
fprint(2, "potential memory leak in test log\n");
log_test_context(s);
append_test_log(s, "potential memory leak in test log");
}
}

View File

@ -48,6 +48,9 @@ static void chk_empty_first(TestState *, void *);
static void chk_first(TestState *, void *);
static void chk_second(TestState *, void *);
static void chk_last(TestState *, void *);
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 chk_ptr_chg(
@ -123,7 +126,7 @@ missing_first(TestState *s)
mk_log_data(&ld);
ld.state.first_log = 0;
append_test_log(&ld.state, "baz");
chk_ptr_eq(s, "first_log", ld.state.first_log, &ld.second);
test_context_with(s, "first_log", mf_chk_first, &ld);
test_context_with(s, "last_log", chk_last, &ld);
}
@ -198,6 +201,37 @@ chk_last(TestState *s, void *ptr)
free(ld->state.last_log);
}
static void
mf_chk_first(TestState *s, void *ptr)
{
LogData *ld = ptr;
chk_ptr_eq(s, 0, ld->state.first_log, &ld->second);
test_context_with(s, "next", mf_chk_second, ptr);
}
static void
mf_chk_second(TestState *s, void *ptr)
{
LogData *ld = ptr;
TestLogEntry *e = ld->second.next;
chk_str_eq(s, "text", e->text, "<no context>");
test_context_with(s, "next", mf_chk_third, ptr);
}
static void
mf_chk_third(TestState *s, void *ptr)
{
LogData *ld = ptr;
TestLogEntry *e = ld->second.next->next;
chk_str_eq(
s,
"text",
e->text,
"potential memory leak in test log"
);
chk_ptr_eq(s, "next", e->next, ld->state.last_log);
}
static void
mk_log_data(LogData *ld)
{