Mercurial > hg > th-libs
changeset 342:09c2f6abf694
Fix memory leaks in test suite.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 23 Feb 2016 22:58:01 +0200 |
parents | 1040f51bf770 |
children | 2b58dd3f5e6c |
files | tests.c |
diffstat | 1 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/tests.c Tue Feb 23 21:59:45 2016 +0200 +++ b/tests.c Tue Feb 23 22:58:01 2016 +0200 @@ -118,13 +118,17 @@ } +void test_end(test_ctx *ctx) +{ + th_free_r(&ctx->header); + th_free_r(&ctx->res); +} + + void test_start_v(test_ctx *ctx, const char *fmt, va_list ap) { tests_total++; - - th_free_r(&ctx->header); - th_free_r(&ctx->res); - + test_end(ctx); ctx->header = th_strdup_vprintf(fmt, ap); } @@ -207,6 +211,7 @@ char *str = th_strdup_vprintf(fmt, tmp); test_result_msg(&ctx, str != NULL, "result NULL"); th_free(str); + test_end(&ctx); } @@ -250,18 +255,21 @@ test_ctx ctx; test_init(&ctx); \ test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ test_result(&ctx, ( fun (str1, str2) == 0) == ret); \ + test_end(&ctx); \ } while (0) #define TEST2B(fun, str1, str2, ret) do { \ test_ctx ctx; test_init(&ctx); \ test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ test_result(&ctx, fun (str1, str2) == ret); \ + test_end(&ctx); \ } while (0) #define TEST3(fun, str1, str2, len, ret) do { \ test_ctx ctx; test_init(&ctx); \ test_start(&ctx, # fun "('%s', '%s', %d)", str1, str2, len); \ test_result(&ctx, ( fun (str1, str2, len) == 0) == ret); \ + test_end(&ctx); \ } while (0)