# HG changeset patch # User Matti Hamalainen # Date 1456261081 -7200 # Node ID 09c2f6abf69413d713b628fa4c7afdef34fa5e86 # Parent 1040f51bf770196a6b1d3ff2b11cd0d33df18f42 Fix memory leaks in test suite. diff -r 1040f51bf770 -r 09c2f6abf694 tests.c --- 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)