From 0442ea22b86e5c008dae5d452cdbfbd3f5020ff6 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Tue, 21 Nov 2017 23:01:39 +0100 Subject: sms_queue_test: sanitize: clean up talloc contexts when done To avoid sanitizer build failures, ensure that the talloc contexts are empty when done and free them. Separate the msgb context from the overall talloc context for clarity: if nested, the outer one would contain two blocks. Change the "sms_queue_test" context from 1 byte to 0 in order to get a size of zero in the end. Change-Id: If08ba48ab9c28bf3c2db4014837c1304cec04aaf --- tests/sms_queue/sms_queue_test.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/sms_queue/sms_queue_test.c b/tests/sms_queue/sms_queue_test.c index 0d073db01..0ff636e79 100644 --- a/tests/sms_queue/sms_queue_test.c +++ b/tests/sms_queue/sms_queue_test.c @@ -197,8 +197,10 @@ static struct log_info info = { int main(int argc, char **argv) { - talloc_ctx = talloc_named_const(NULL, 1, "sms_queue_test"); - msgb_talloc_ctx_init(talloc_ctx, 0); + void *msgb_ctx; + + talloc_ctx = talloc_named_const(NULL, 0, "sms_queue_test"); + msgb_ctx = msgb_talloc_ctx_init(NULL, 0); osmo_init_logging(&info); OSMO_ASSERT(osmo_stderr_target); @@ -211,5 +213,23 @@ int main(int argc, char **argv) test_next_sms(); printf("Done\n"); + if (talloc_total_blocks(msgb_ctx) != 1 + || talloc_total_size(msgb_ctx) != 0) { + talloc_report_full(msgb_ctx, stderr); + fflush(stderr); + } + + OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1); + OSMO_ASSERT(talloc_total_size(msgb_ctx) == 0); + talloc_free(msgb_ctx); + + if (talloc_total_blocks(talloc_ctx) != 1 + || talloc_total_size(talloc_ctx) != 0) + talloc_report_full(talloc_ctx, stderr); + + OSMO_ASSERT(talloc_total_blocks(talloc_ctx) == 1); + OSMO_ASSERT(talloc_total_size(talloc_ctx) == 0); + talloc_free(talloc_ctx); + return 0; } -- cgit v1.2.3