fix ctrl_test sanitizer issues

Add logging to root ctx, add msgb ctx to root ctx, free wqueue to simulate the
msgb being sent, and assert final talloc size.

Change-Id: Ief3d5e7b6c4d781b3854e230e45a67d5281b94cd
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
index b7b30c3..8bb917b 100644
--- a/tests/ctrl/ctrl_test.c
+++ b/tests/ctrl/ctrl_test.c
@@ -397,6 +397,7 @@
 	printf("ctrl_handle_msg() returned %d\n", result);
 
 	OSMO_ASSERT(result == CTRL_CMD_HANDLED);
+	talloc_free(msg);
 
 	/* Expecting a ctrl_cmd_def as well as the cmd to still be allocated */
 	if (talloc_total_size(ctx) <= ctx_size_before_defer) {
@@ -408,6 +409,9 @@
 	printf("invoking ctrl_test_defer_cb() asynchronously\n");
 	ctrl_test_defer_cb(test_defer_cd);
 
+	/* simulate sending of the reply */
+	osmo_wqueue_clear(&ccon->write_queue);
+
 	/* And now the deferred cmd should be cleaned up completely. */
 	if (talloc_total_size(ctx) != ctx_size_before_defer) {
 		printf("mem leak!\n");
@@ -438,7 +442,8 @@
 int main(int argc, char **argv)
 {
 	ctx = talloc_named_const(NULL, 1, "ctrl_test");
-	osmo_init_logging(&info);
+	osmo_init_logging2(ctx, &info);
+	msgb_talloc_ctx_init(ctx, 0);
 
 	printf("Checking ctrl types...\n");
 
@@ -455,5 +460,11 @@
 
 	test_deferred_cmd();
 
+	/* Expecting root ctx + msgb root ctx + 5 logging elements */
+	if (talloc_total_blocks(ctx) != 7) {
+		talloc_report_full(ctx, stdout);
+		OSMO_ASSERT(false);
+	}
+
 	return 0;
 }