mirror of https://gerrit.osmocom.org/gapk
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().
This commit is contained in:
parent
750c896b4a
commit
f23b747364
|
@ -18,4 +18,5 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
void osmo_gapk_set_talloc_ctx(void *ctx);
|
||||
void osmo_gapk_log_init(int subsys);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
10
src/common.c
10
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;
|
||||
|
|
|
@ -2,6 +2,7 @@ LIBOSMOGAPK_1.0 {
|
|||
global:
|
||||
|
||||
osmo_gapk_log_init;
|
||||
osmo_gapk_set_talloc_ctx;
|
||||
|
||||
osmo_gapk_pq;
|
||||
osmo_gapk_pq_item;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue