From: Scott Worley Date: Thu, 14 Sep 2023 06:54:52 +0000 (-0700) Subject: test: Fix memory leak X-Git-Tag: v1.0.1~2 X-Git-Url: http://git.scottworley.com/tl-append/commitdiff_plain/ee028f60297c4f800d6bcd3433b4263e0c8714ca test: Fix memory leak --- diff --git a/tl-append-test.c b/tl-append-test.c index ee5d3f7..30cfaae 100644 --- a/tl-append-test.c +++ b/tl-append-test.c @@ -28,9 +28,12 @@ const ex_t CONSUMED = {((time_t)-2), ((time_t)-2), NULL}; static int is_end(ex_t exp) { return exp.a == END.a && exp.b == END.b && exp.message == END.message; } +static void consume(ex_t *exp) { + exp->a = CONSUMED.a; + exp->b = CONSUMED.b; +} static int is_consumed(ex_t exp) { - return exp.a == CONSUMED.a && exp.b == CONSUMED.b && - exp.message == CONSUMED.message; + return exp.a == CONSUMED.a && exp.b == CONSUMED.b; } static ex_t expectation(time_t a, time_t b, const char *message) { ex_t exp; @@ -126,7 +129,7 @@ static void verify_log_contents(const ex_t exps[]) { static void consume_expectation(ex_t exps[], const char *line) { for (size_t i = 0; !is_end(exps[i]); i++) { if (line_problem(&exps[i], line) == NULL) { - exps[i] = CONSUMED; + consume(&exps[i]); return; } } @@ -305,6 +308,9 @@ static void write_concurrently() { } results[PARALLELISM] = END; verify_log_contents_unordered(results); + for (int i = 0; i < PARALLELISM; i++) { + free((void *)results[i].message); + } } int main() {