improve talloc memory leak debugging

* switch to talloc_report_full() on SIGUSR1
* include asn1-internal allocations in talloc report

Change-Id: I14fff863449971024002e0d5465fb7a964d67095
diff --git a/include/osmocom/rspro/asn_internal.h b/include/osmocom/rspro/asn_internal.h
index 561dcf6..abd487f 100644
--- a/include/osmocom/rspro/asn_internal.h
+++ b/include/osmocom/rspro/asn_internal.h
@@ -23,10 +23,12 @@
 #define	ASN1C_ENVIRONMENT_VERSION	924	/* 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)
+#include <osmocom/core/talloc.h>
+extern __thread void *talloc_asn1_ctx;
+#define CALLOC(nmemb, size)     talloc_zero_size(talloc_asn1_ctx, (nmemb) * (size))
+#define MALLOC(size)            talloc_size(talloc_asn1_ctx, size)
+#define REALLOC(oldptr, size)   talloc_realloc_size(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/src/bankd_main.c b/src/bankd_main.c
index 178d09f..54c20ca 100644
--- a/src/bankd_main.c
+++ b/src/bankd_main.c
@@ -330,7 +330,7 @@
 		struct bankd_worker *worker;
 		/* main thread */
 		fprintf(stderr, "=== Talloc Report of main thread:\n");
-		talloc_report(g_tall_ctx, stderr);
+		talloc_report_full(g_tall_ctx, stderr);
 
 		/* iterate over worker threads and ask them to dump their talloc state */
 		pthread_mutex_lock(&g_bankd->workers_mutex);
@@ -341,7 +341,7 @@
 	} else {
 		/* worker thread */
 		fprintf(stderr, "=== Talloc Report of %s\n", g_worker->name);
-		talloc_report(g_worker->tall_ctx, stderr);
+		talloc_report_full(g_worker->tall_ctx, stderr);
 	}
 }
 
diff --git a/src/remsim_client.c b/src/remsim_client.c
index 38092b4..de926f7 100644
--- a/src/remsim_client.c
+++ b/src/remsim_client.c
@@ -164,7 +164,7 @@
 static void handle_sig_usr1(int signal)
 {
 	OSMO_ASSERT(signal == SIGUSR1);
-	talloc_report(g_tall_ctx, stderr);
+	talloc_report_full(g_tall_ctx, stderr);
 }
 
 static void printf_help()
@@ -229,6 +229,7 @@
 	int rc;
 
 	g_tall_ctx = talloc_named_const(NULL, 0, "global");
+	talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
 
 	osmo_init_logging2(g_tall_ctx, &log_info);
 
diff --git a/src/server/remsim_server.c b/src/server/remsim_server.c
index cabb5f9..57e0733 100644
--- a/src/server/remsim_server.c
+++ b/src/server/remsim_server.c
@@ -15,12 +15,14 @@
 
 struct rspro_server *g_rps;
 void *g_tall_ctx;
+__thread void *talloc_asn1_ctx;
+
 struct osmo_fd g_event_ofd;
 
 static void handle_sig_usr1(int signal)
 {
 	OSMO_ASSERT(signal == SIGUSR1);
-	talloc_report(g_tall_ctx, stderr);
+	talloc_report_full(g_tall_ctx, stderr);
 }
 
 int main(int argc, char **argv)
@@ -28,6 +30,7 @@
 	int rc;
 
 	g_tall_ctx = talloc_named_const(NULL, 0, "global");
+	talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
 
 	osmo_init_logging2(g_tall_ctx, &log_info);
 
diff --git a/src/simtrace2-remsim_client.c b/src/simtrace2-remsim_client.c
index f87ce85..8f01b2f 100644
--- a/src/simtrace2-remsim_client.c
+++ b/src/simtrace2-remsim_client.c
@@ -679,7 +679,7 @@
 static void handle_sig_usr1(int signal)
 {
 	OSMO_ASSERT(signal == SIGUSR1);
-	talloc_report(g_tall_ctx, stderr);
+	talloc_report_full(g_tall_ctx, stderr);
 }
 
 static void print_welcome(void)
@@ -817,6 +817,7 @@
 	signal(SIGUSR1, handle_sig_usr1);
 
 	g_tall_ctx = talloc_named_const(NULL, 0, "global");
+	talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
 	osmo_init_logging2(g_tall_ctx, &log_info);
 
 	rc = libusb_init(NULL);