summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/tests/common.c9
-rw-r--r--server/tests/common.h2
-rw-r--r--server/tests/fail_over-tests.c2
-rw-r--r--server/tests/resolv-tests.c4
4 files changed, 11 insertions, 6 deletions
diff --git a/server/tests/common.c b/server/tests/common.c
index 5b341abce..dad9dc66b 100644
--- a/server/tests/common.c
+++ b/server/tests/common.c
@@ -47,7 +47,7 @@ _check_leaks(TALLOC_CTX *ctx, size_t bytes, const char *location)
bytes_allocated = talloc_total_size(ctx);
if (bytes_allocated != bytes) {
fprintf(stderr, "Leak report for %s:\n", location);
- talloc_report_full(NULL, stderr);
+ talloc_report_full(ctx, stderr);
fail("%s: memory leaks detected, %d bytes still allocated",
location, bytes_allocated - bytes);
}
@@ -91,14 +91,17 @@ void
leak_check_setup(void)
{
talloc_enable_null_tracking();
+ global_talloc_context = talloc_new(NULL);
+ fail_unless(global_talloc_context != NULL, "talloc_new failed");
+ check_leaks_push(global_talloc_context);
}
void
leak_check_teardown(void)
{
+ check_leaks_pop(global_talloc_context);
if (snapshot_stack != NULL) {
fail("Exiting with a non-empty stack");
}
- talloc_free(talloc_autofree_context());
- check_leaks(NULL, 0);
+ check_leaks(global_talloc_context, 0);
}
diff --git a/server/tests/common.h b/server/tests/common.h
index 39a2b8e07..44e2d9afa 100644
--- a/server/tests/common.h
+++ b/server/tests/common.h
@@ -3,6 +3,8 @@
#include <talloc.h>
+TALLOC_CTX *global_talloc_context;
+
#define check_leaks(ctx, bytes) _check_leaks((ctx), (bytes), __location__)
void _check_leaks(TALLOC_CTX *ctx,
size_t bytes,
diff --git a/server/tests/fail_over-tests.c b/server/tests/fail_over-tests.c
index c3e9dfe52..e794f03b5 100644
--- a/server/tests/fail_over-tests.c
+++ b/server/tests/fail_over-tests.c
@@ -62,7 +62,7 @@ setup_test(void)
struct test_ctx *ctx;
int ret;
- ctx = talloc_zero(NULL, struct test_ctx);
+ ctx = talloc_zero(global_talloc_context, struct test_ctx);
fail_if(ctx == NULL, "Could not allocate memory for test context");
ctx->ev = tevent_context_init(ctx);
diff --git a/server/tests/resolv-tests.c b/server/tests/resolv-tests.c
index c1b327819..04b9e2e76 100644
--- a/server/tests/resolv-tests.c
+++ b/server/tests/resolv-tests.c
@@ -60,7 +60,7 @@ static int setup_resolv_test(struct resolv_test_ctx **ctx)
struct resolv_test_ctx *test_ctx;
int ret;
- test_ctx = talloc_zero(NULL, struct resolv_test_ctx);
+ test_ctx = talloc_zero(global_talloc_context, struct resolv_test_ctx);
if (test_ctx == NULL) {
fail("Could not allocate memory for test context");
return ENOMEM;
@@ -109,7 +109,7 @@ START_TEST(test_copy_hostent)
sizeof(addr_1), addr_list
};
- ctx = talloc_new(NULL);
+ ctx = talloc_new(global_talloc_context);
fail_if(ctx == NULL);
check_leaks_push(ctx);