pespin has submitted this change. (
https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/42219?usp=email )
Change subject: Use talloc to allocate asn1c decoded structs
......................................................................
Use talloc to allocate asn1c decoded structs
This commit adds talloc support but will still use talloc NULL context
everywhere when allocating memory.
This is already useful since it allows programs enabling null context
tracking to get a report of memory usage.
Related: SYS#5423
Related: OS#6965
Change-Id: I6d885527caa5b60011b4fac341b93026ab1833d9
---
M configure.ac
M debian/control
M include/osmocom/tcap/asn_internal.h
M libosmo-asn1-tcap.pc.in
M src/Makefile.am
M src/tcap.c
M tests/parse/Makefile.am
7 files changed, 27 insertions(+), 8 deletions(-)
Approvals:
laforge: Looks good to me, but someone else must approve
fixeria: Looks good to me, but someone else must approve
pespin: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/configure.ac b/configure.ac
index 5082daf..28aa608 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,6 +31,8 @@
AC_SUBST([ASN_MODULE_CFLAGS])
+PKG_CHECK_MODULES(TALLOC, [talloc >= 2.1.0])
+
# The following test is taken from WebKit's webkit.m4
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fvisibility=hidden "
diff --git a/debian/control b/debian/control
index 2dee434..52ffffe 100644
--- a/debian/control
+++ b/debian/control
@@ -10,6 +10,7 @@
git,
libtool,
pkg-config,
+ libtalloc-dev (>= 2.1.0)
Standards-Version: 3.9.6
Vcs-Browser: https://gitea.osmocom.org/ss7-in-c/libosmo-asn1-tcap
Vcs-Git: https://gitea.osmocom.org/ss7-in-c/libosmo-asn1-tcap
@@ -25,7 +26,9 @@
Package: libosmo-asn1-tcap-dev
Section: libdevel
Architecture: any
-Depends: libosmo-asn1-tcap1 (= ${binary:Version}), ${misc:Depends}
+Depends: libosmo-asn1-tcap1 (= ${binary:Version}),
+ libtalloc-dev (>= 2.1.0),
+ ${misc:Depends}
Multi-Arch: same
Description: Development headers for utility library for ASN.1 of TCAP (SS7)
diff --git a/include/osmocom/tcap/asn_internal.h
b/include/osmocom/tcap/asn_internal.h
index bf5b510..f4337d3 100644
--- a/include/osmocom/tcap/asn_internal.h
+++ b/include/osmocom/tcap/asn_internal.h
@@ -7,6 +7,7 @@
*/
#ifndef ASN_INTERNAL_H
#define ASN_INTERNAL_H
+#include <talloc.h>
#ifndef __EXTENSIONS__
#define __EXTENSIONS__ /* for Sun */
#endif
@@ -34,10 +35,11 @@
#define ASN1C_ENVIRONMENT_VERSION 923 /* Compile-time version
*/
int get_asn1c_environment_version(void); /* Run-time version */
-#define CALLOC(nmemb, size) calloc(nmemb, size)
-#define MALLOC(size) malloc(size)
-#define REALLOC(oldptr, size) realloc(oldptr, size)
-#define FREEMEM(ptr) free(ptr)
+extern void *tcap_talloc_asn1_ctx;
+#define CALLOC(nmemb, size) talloc_zero_size(tcap_talloc_asn1_ctx,
(nmemb) * (size))
+#define MALLOC(size) talloc_size(tcap_talloc_asn1_ctx, size)
+#define REALLOC(oldptr, size)
talloc_realloc_size(tcap_talloc_asn1_ctx, oldptr, size)
+#define FREEMEM(ptr) talloc_free(ptr)
#define asn_debug_indent 0
#define ASN_DEBUG_INDENT_ADD(i) do{}while(0)
diff --git a/libosmo-asn1-tcap.pc.in b/libosmo-asn1-tcap.pc.in
index 17971a1..80dd622 100644
--- a/libosmo-asn1-tcap.pc.in
+++ b/libosmo-asn1-tcap.pc.in
@@ -6,5 +6,6 @@
Name: ASN.1 library for TCAP protocol (SS7)
Description: C Utility Library
Version: @VERSION@
+Requires.private: talloc
Libs: -L${libdir} -losmo-asn1-tcap
Cflags: -I${includedir}/
diff --git a/src/Makefile.am b/src/Makefile.am
index 6c2f830..42089af 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-AM_CFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/src/skel
$(ASN_MODULE_CFLAGS)
+AM_CFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/src/skel
$(ASN_MODULE_CFLAGS) $(TALLOC_CFLAGS)
SKEL_SRC = \
skel/ANY.c \
@@ -201,6 +201,8 @@
libosmo_asn1_tcap_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined
-export-symbols-regex '^osmo_'
+libosmo_asn1_tcap_la_LIBADD = $(TALLOC_LIBS)
+
libosmo_asn1_tcap_la_SOURCES = \
tcap.c \
$(ASN_MODULE_SRC)
@@ -239,6 +241,13 @@
# #include <...> in *.c and *.h files
cd $(top_srcdir)/src/gen && \
../../move-asn1-header-files.sh osmocom/tcap $(ASN_MODULE_INC)
+#Patch mem alloc defines to use talloc:
+ sed -i "s/#define\tASN_INTERNAL_H/#define\tASN_INTERNAL_H\n#include
<talloc.h>/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h
+ sed -i "s/#define\tCALLOC/extern void
*tcap_talloc_asn1_ctx;\n#define\tCALLOC/g"
$(top_srcdir)/include/osmocom/tcap/asn_internal.h
+ sed -i "s/calloc(nmemb, size)/talloc_zero_size(tcap_talloc_asn1_ctx,
(nmemb) * (size))/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h
+ sed -i "s/malloc(size)/talloc_size(tcap_talloc_asn1_ctx, size)/g"
$(top_srcdir)/include/osmocom/tcap/asn_internal.h
+ sed -i "s/realloc(oldptr,
size)/talloc_realloc_size(tcap_talloc_asn1_ctx, oldptr, size)/g"
$(top_srcdir)/include/osmocom/tcap/asn_internal.h
+ sed -i "s/free(ptr)/talloc_free(ptr)/g"
$(top_srcdir)/include/osmocom/tcap/asn_internal.h
# Move skeleton *.c files to src/skel
rm -rf $(top_srcdir)/src/skel
mkdir $(top_srcdir)/src/skel
diff --git a/src/tcap.c b/src/tcap.c
index 68c7d9c..f5303ac 100644
--- a/src/tcap.c
+++ b/src/tcap.c
@@ -26,6 +26,8 @@
#include <osmocom/tcap/asn_codecs.h>
#include <osmocom/tcap/TCAP_TCMessage.h>
+void *tcap_talloc_asn1_ctx;
+
int osmo_asn1_tcap_decode(struct TCAP_TCMessage *tcapmsg, const uint8_t *data,
size_t data_len)
{
diff --git a/tests/parse/Makefile.am b/tests/parse/Makefile.am
index 821865d..1a449fe 100644
--- a/tests/parse/Makefile.am
+++ b/tests/parse/Makefile.am
@@ -1,8 +1,8 @@
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_srcdir)/src
-AM_CFLAGS = -Wall
+AM_CFLAGS = -Wall $(TALLOC_CFLAGS)
AM_LDFLAGS = -no-install
-LDADD = $(top_builddir)/src/.libs/libosmo-asn1-tcap.a
+LDADD = $(top_builddir)/src/.libs/libosmo-asn1-tcap.a $(TALLOC_LIBS)
check_PROGRAMS = \
tcap_parse_test \
--
To view, visit https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/42219?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmo-asn1-tcap
Gerrit-Branch: master
Gerrit-Change-Id: I6d885527caa5b60011b4fac341b93026ab1833d9
Gerrit-Change-Number: 42219
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: lynxis lazus <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>