aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-09-09 14:23:56 +0300
committerVadim Yanitskiy <axilirator@gmail.com>2017-09-10 15:04:48 +0300
commita2a6317a963e0e55b760368f51c66a8e667b92f0 (patch)
treeec52cc2b3c591a1b3054405bafea8622dcb171e3
parent4a77ee720a79e5e8f1e7b9e975d27c19c094b316 (diff)
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().
-rw-r--r--include/osmocom/gapk/common.h1
-rw-r--r--src/benchmark.c5
-rw-r--r--src/codec_amr.c5
-rw-r--r--src/codec_efr.c4
-rw-r--r--src/common.c10
-rw-r--r--src/libosmogapk.map1
-rw-r--r--src/procqueue.c5
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 <osmocom/gapk/benchmark.h>
#include <osmocom/gapk/codecs.h>
+/* 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 <opencore-amrnb/interf_dec.h>
#include <opencore-amrnb/interf_enc.h>
+/* 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 <opencore-amrnb/interf_dec.h>
#include <opencore-amrnb/interf_enc.h>
+/* 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 <http://www.gnu.org/licenses/>.
*/
+#include <talloc.h>
+
+/* 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 <osmocom/gapk/procqueue.h>
#include <osmocom/gapk/logging.h>
+/* 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;