diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index e2b0a25880..02493b2fb4 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -5,7 +5,7 @@ #include "test-common.h" #include - +#include /* _exit() */ #include /* for fatal tests */ /* To test the firing of i_assert, we need non-local jumps, i.e. setjmp */ @@ -448,3 +448,13 @@ int test_run_named_with_fatals(const char *match, struct named_test tests[], test_run_named_fatals(fatals, match); return test_deinit(); } + +void ATTR_NORETURN +test_exit(int status) +{ + i_free_and_null(expected_error_str); + i_free_and_null(test_prefix); + (void)t_pop(); /* as we were within a T_BEGIN { tests[i].func(); } T_END */ + lib_deinit(); + _exit(status); +} diff --git a/src/lib-test/test-common.h b/src/lib-test/test-common.h index b956e7d78a..2afddbcc3f 100644 --- a/src/lib-test/test-common.h +++ b/src/lib-test/test-common.h @@ -73,4 +73,7 @@ int test_run_named_with_fatals(const char *match, struct named_test tests[], #define FATAL_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */ #define FATAL_NAMED(x) { .name = #x , .func = x }, +/* If a fork() wants to exit(), then this will avoid valgrind leak errors */ +void test_exit(int status) ATTR_NORETURN; + #endif diff --git a/src/lib/test-istream-unix.c b/src/lib/test-istream-unix.c index a0890bf50d..dadf42c919 100644 --- a/src/lib/test-istream-unix.c +++ b/src/lib/test-istream-unix.c @@ -176,7 +176,7 @@ void test_istream_unix(void) case 0: i_close_fd(&fd[0]); test_istream_unix_client(fd[1]); - _exit(0); + test_exit(0); default: i_close_fd(&fd[1]); test_istream_unix_server(fd[0]);