From e39f6cd7528895d9dd67a4d4ebddda764422776f Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 10 Apr 2019 00:33:46 +0200 Subject: [PATCH] smpp: Make libsmpp34 use talloc for its allocations We are just introducing smpp34_set_memory_functions() in libsmpp34 to allow applications like OsmoMSC to provide their own heap allocator callback functions. Let's used this to integrate with talloc and hence allow talloc tracking/debugging for libsmpp34 internal allocations. Depends: libsmpp34 Change-Id I3656117115e89638c093bfbcbc4369ce302f7a94 Change-Id: Ie2725ffab6a225813e65768735f01678e2022128 Related: OS#3913 --- src/libmsc/smpp_openbsc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/libmsc/smpp_openbsc.c b/src/libmsc/smpp_openbsc.c index e6eb0102a..bbfc5008f 100644 --- a/src/libmsc/smpp_openbsc.c +++ b/src/libmsc/smpp_openbsc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -52,6 +53,31 @@ #define VSUB_USE_SMPP "SMPP" #define VSUB_USE_SMPP_CMD "SMPP-cmd" +/* talloc integration for libsmpp34 */ + +static struct smsc *g_smsc; + +static void *smpp34_talloc_malloc(size_t sz) +{ + return talloc_size(g_smsc, sz); +} + +static void *smpp34_talloc_realloc(void *ptr, size_t sz) +{ + return talloc_realloc_size(g_smsc, ptr, sz); +} + +static void smpp34_talloc_free(void *ptr) +{ + talloc_free(ptr); +} + +static const struct smpp34_memory_functions smpp34_talloc = { + .malloc_fun = smpp34_talloc_malloc, + .realloc_fun = smpp34_talloc_realloc, + .free_fun = smpp34_talloc_free, +}; + /*! \brief find vlr_subscr for a given SMPP NPI/TON/Address */ static struct vlr_subscr *subscr_by_dst(struct gsm_network *net, uint8_t npi, uint8_t ton, @@ -790,6 +816,7 @@ int smpp_openbsc_alloc_init(void *ctx) LOGP(DSMPP, LOGL_FATAL, "Cannot allocate smsc struct\n"); return -1; } + smpp34_set_memory_functions(&smpp34_talloc); return smpp_vty_init(); }