From 28c8a4bf2fbee013a2c82e19063940ec4cc80414 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 11 Jul 2018 02:58:00 +0200 Subject: add osmo_xua_msg_tall_ctx_init() So far the tall_xua ctx used to allocate from in xua_msg_alloc() was never initialized, actually hiding memory leaks from the talloc report. Add this API to allow branching the xua_msg ctx off a sane root ctx. Explicitly initialize tall_xua to NULL, so that, if xua_msg_ctx_init() isn't called, tall_xua is still guaranteed to not be a random pointer. osmo-bsc will use this function to hook the tall_xua ctx to osmo-bsc's own root ctx. Change-Id: I618878680a096a7f7fc2d83098590f2e4cb08870 --- include/osmocom/sigtran/xua_msg.h | 2 ++ src/xua_msg.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/osmocom/sigtran/xua_msg.h b/include/osmocom/sigtran/xua_msg.h index 423adbc..e912e02 100644 --- a/include/osmocom/sigtran/xua_msg.h +++ b/include/osmocom/sigtran/xua_msg.h @@ -69,6 +69,8 @@ struct xua_msg_event_map { extern const struct xua_dialect xua_dialect_sua; extern const struct xua_dialect xua_dialect_m3ua; +void osmo_xua_msg_tall_ctx_init(void *ctx); + struct xua_msg *xua_msg_alloc(void); void xua_msg_free(struct xua_msg *msg); diff --git a/src/xua_msg.c b/src/xua_msg.c index d56009f..ed0cdc7 100644 --- a/src/xua_msg.c +++ b/src/xua_msg.c @@ -33,7 +33,13 @@ #include #include -static void *tall_xua; +static void *tall_xua = NULL; + +/* Allocate the root talloc context used for xua_msg_alloc(). */ +void osmo_xua_msg_tall_ctx_init(void *ctx) +{ + tall_xua = talloc_named_const(ctx, 0, "xua_msg"); +} struct xua_msg *xua_msg_alloc(void) { -- cgit v1.2.3