Change in ...osmo-remsim[master]: track libulfius and jansson memory allocations with talloc

laforge gerrit-no-reply at lists.osmocom.org
Sun Jul 21 18:46:58 UTC 2019


laforge has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/osmo-remsim/+/14883 )

Change subject: track libulfius and jansson memory allocations with talloc
......................................................................

track libulfius and jansson memory allocations with talloc

Change-Id: I0ad63a79a806b420ea0de42b67726da36ebac828
---
M configure.ac
M src/server/Makefile.am
M src/server/remsim_server.c
M src/server/rest_api.c
M src/server/rest_api.h
5 files changed, 40 insertions(+), 5 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/configure.ac b/configure.ac
index e87c8c8..2fc603d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,7 @@
 	[osmo_ac_build_server="$enableval"],[osmo_ac_build_server="yes"])
 if test "$osmo_ac_build_server" = "yes"; then
 	PKG_CHECK_MODULES(ULFIUS, libulfius)
+	PKG_CHECK_MODULES(ORCANIA, liborcania)
 	PKG_CHECK_MODULES(JANSSON, jansson)
 	AC_DEFINE(BUILD_SERVER, 1, [Define if we want to build osmo-remsim-server])
 fi
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index ce114b6..f6278a3 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -2,7 +2,7 @@
 AM_CFLAGS = -Wall -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src \
 	    -I$(top_srcdir)/include/osmocom/rspro \
 	    $(OSMOCORE_CFLAGS) $(OSMOGSM_CFLAGS) $(OSMOABIS_CFLAGS) \
-	    $(ULFIUS_CFLAGS) $(JANSSON_CFLAGS)
+	    $(ULFIUS_CFLAGS) $(JANSSON_CFLAGS) $(ORCANIA_CFLAGS)
 
 noinst_HEADERS = rspro_server.h rest_api.h
 
@@ -11,7 +11,7 @@
 osmo_remsim_server_SOURCES = remsim_server.c rspro_server.c rest_api.c \
 			     ../rspro_util.c ../slotmap.c ../debug.c
 osmo_remsim_server_LDADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(OSMOABIS_LIBS) \
-			   $(ULFIUS_LIBS) $(JANSSON_LIBS) \
+			   $(ULFIUS_LIBS) $(JANSSON_LIBS) $(ORCANIA_LIBS) \
 			   $(top_builddir)/src/libosmo-rspro.la
 
 # as suggested in http://lists.gnu.org/archive/html/automake/2009-03/msg00011.html
diff --git a/src/server/remsim_server.c b/src/server/remsim_server.c
index a8502e4..70cbedc 100644
--- a/src/server/remsim_server.c
+++ b/src/server/remsim_server.c
@@ -27,10 +27,12 @@
 
 int main(int argc, char **argv)
 {
+	void *talloc_rest_ctx;
 	int rc;
 
 	g_tall_ctx = talloc_named_const(NULL, 0, "global");
 	talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
+	talloc_rest_ctx = talloc_named_const(g_tall_ctx, 0, "rest");
 	msgb_talloc_ctx_init(g_tall_ctx, 0);
 
 	osmo_init_logging2(g_tall_ctx, &log_info);
@@ -56,7 +58,7 @@
 
 	signal(SIGUSR1, handle_sig_usr1);
 
-	rc = rest_api_init(9997);
+	rc = rest_api_init(talloc_rest_ctx, 9997);
 	if (rc < 0)
 		goto out_eventfd;
 
diff --git a/src/server/rest_api.c b/src/server/rest_api.c
index b990664..969f672 100644
--- a/src/server/rest_api.c
+++ b/src/server/rest_api.c
@@ -1,9 +1,11 @@
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <pthread.h>
 
 #include <jansson.h>
 #include <ulfius.h>
+#include <orcania.h>
 
 #include <osmocom/core/utils.h>
 #include <osmocom/core/linuxlist.h>
@@ -461,13 +463,43 @@
 };
 
 static struct _u_instance g_instance;
+static pthread_mutex_t g_tall_lock = PTHREAD_MUTEX_INITIALIZER;
+static void *g_tall_rest;
 
-int rest_api_init(uint16_t port)
+static void *my_o_malloc(size_t sz)
+{
+	void *obj;
+	pthread_mutex_lock(&g_tall_lock);
+	obj = talloc_size(g_tall_rest, sz);
+	pthread_mutex_unlock(&g_tall_lock);
+	return obj;
+}
+
+static void *my_o_realloc(void *obj, size_t sz)
+{
+	pthread_mutex_lock(&g_tall_lock);
+	obj = talloc_realloc_size(g_tall_rest, obj, sz);
+	pthread_mutex_unlock(&g_tall_lock);
+	return obj;
+}
+
+static void my_o_free(void *obj)
+{
+	pthread_mutex_lock(&g_tall_lock);
+	talloc_free(obj);
+	pthread_mutex_unlock(&g_tall_lock);
+}
+
+int rest_api_init(void *ctx, uint16_t port)
 {
 	int i;
 
+	g_tall_rest = ctx;
+	o_set_alloc_funcs(my_o_malloc, my_o_realloc, my_o_free);
+
 	if (ulfius_init_instance(&g_instance, port, NULL, NULL) != U_OK)
 		return -1;
+	g_instance.mhd_response_copy_data = 1;
 
 	for (i = 0; i < ARRAY_SIZE(api_endpoints); i++)
 		ulfius_add_endpoint(&g_instance, &api_endpoints[i]);
diff --git a/src/server/rest_api.h b/src/server/rest_api.h
index 87269e8..dfba65d 100644
--- a/src/server/rest_api.h
+++ b/src/server/rest_api.h
@@ -1,5 +1,5 @@
 #pragma once
 #include <stdint.h>
 
-int rest_api_init(uint16_t port);
+int rest_api_init(void *ctx, uint16_t port);
 void rest_api_fini(void);

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-remsim/+/14883
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-Change-Id: I0ad63a79a806b420ea0de42b67726da36ebac828
Gerrit-Change-Number: 14883
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190721/24048e4d/attachment.html>


More information about the gerrit-log mailing list