From f23b74736458d2415dd1dfec0559af44e6353574 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sat, 9 Sep 2017 14:23:56 +0300 Subject: [PATCH] libosmogapk: introduce the internal root talloc context In order to simplify memory leak debugging, this change introduces the library's internal talloc context that may be changed by external application by calling the osmo_gapk_set_talloc_ctx(). --- include/osmocom/gapk/common.h | 1 + src/benchmark.c | 5 ++++- src/codec_amr.c | 5 ++++- src/codec_efr.c | 4 +++- src/common.c | 10 ++++++++++ src/libosmogapk.map | 1 + src/procqueue.c | 5 ++++- 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/osmocom/gapk/common.h b/include/osmocom/gapk/common.h index 138882c..920824e 100644 --- a/include/osmocom/gapk/common.h +++ b/include/osmocom/gapk/common.h @@ -18,4 +18,5 @@ #pragma once +void osmo_gapk_set_talloc_ctx(void *ctx); void osmo_gapk_log_init(int subsys); diff --git a/src/benchmark.c b/src/benchmark.c index c523f55..b3bb60b 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -23,6 +23,9 @@ #include #include +/* Internal root talloc context */ +extern TALLOC_CTX *gapk_root_ctx; + struct osmo_gapk_bench_cycles * osmo_gapk_bench_codec[_CODEC_MAX] = { NULL }; @@ -31,7 +34,7 @@ int osmo_gapk_bench_enable(enum osmo_gapk_codec_type codec) struct osmo_gapk_bench_cycles *bench; /* Allocate zero-initialized memory */ - bench = talloc_zero(NULL, struct osmo_gapk_bench_cycles); + bench = talloc_zero(gapk_root_ctx, struct osmo_gapk_bench_cycles); if (!bench) return -ENOMEM; diff --git a/src/codec_amr.c b/src/codec_amr.c index a2787d7..9c96290 100644 --- a/src/codec_amr.c +++ b/src/codec_amr.c @@ -32,6 +32,9 @@ #include #include +/* Internal root talloc context */ +extern TALLOC_CTX *gapk_root_ctx; + struct codec_amr_state { void *encoder; void *decoder; @@ -43,7 +46,7 @@ codec_amr_init(void) { struct codec_amr_state *st; - st = talloc_zero(NULL, struct codec_amr_state); + st = talloc_zero(gapk_root_ctx, struct codec_amr_state); if (!st) return NULL; diff --git a/src/codec_efr.c b/src/codec_efr.c index ddd3790..9804bd9 100644 --- a/src/codec_efr.c +++ b/src/codec_efr.c @@ -32,6 +32,8 @@ #include #include +/* Internal root talloc context */ +extern TALLOC_CTX *gapk_root_ctx; struct codec_efr_state { void *encoder; @@ -44,7 +46,7 @@ codec_efr_init(void) { struct codec_efr_state *st; - st = talloc_zero(NULL, struct codec_efr_state); + st = talloc_zero(gapk_root_ctx, struct codec_efr_state); if (!st) return NULL; diff --git a/src/common.c b/src/common.c index 1984d29..9448362 100644 --- a/src/common.c +++ b/src/common.c @@ -17,6 +17,16 @@ * along with gapk. If not, see . */ +#include + +/* Internal root talloc context */ +TALLOC_CTX *gapk_root_ctx = NULL; + +void osmo_gapk_set_talloc_ctx(void *ctx) +{ + gapk_root_ctx = ctx; +} + /* Internal GAPK logging */ int osmo_gapk_log_init_complete = 0; int osmo_gapk_log_subsys; diff --git a/src/libosmogapk.map b/src/libosmogapk.map index d8b8af3..a6ce08d 100644 --- a/src/libosmogapk.map +++ b/src/libosmogapk.map @@ -2,6 +2,7 @@ LIBOSMOGAPK_1.0 { global: osmo_gapk_log_init; +osmo_gapk_set_talloc_ctx; osmo_gapk_pq; osmo_gapk_pq_item; diff --git a/src/procqueue.c b/src/procqueue.c index dcf55bc..3303cce 100644 --- a/src/procqueue.c +++ b/src/procqueue.c @@ -27,6 +27,9 @@ #include #include +/* Internal root talloc context */ +extern TALLOC_CTX *gapk_root_ctx; + /* crate a new (empty) processing queue */ struct osmo_gapk_pq * osmo_gapk_pq_create(void) @@ -34,7 +37,7 @@ osmo_gapk_pq_create(void) struct osmo_gapk_pq *pq; /* Allocate memory for a new processing queue */ - pq = talloc_zero(NULL, struct osmo_gapk_pq); + pq = talloc_zero(gapk_root_ctx, struct osmo_gapk_pq); if (!pq) return NULL;