summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-09-09 14:44:24 +0300
committerVadim Yanitskiy <axilirator@gmail.com>2017-12-31 12:20:59 +0100
commit5cabe1eeec55421954c052951a3dba00018af7cf (patch)
tree16d47eabf0fb04403180508d0595a7fa14cc4b3e
parentf23b74736458d2415dd1dfec0559af44e6353574 (diff)
osmo-gapk: use talloc for memory management
-rw-r--r--src/app_osmo_gapk.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/app_osmo_gapk.c b/src/app_osmo_gapk.c
index 720e08b..2ce0a31 100644
--- a/src/app_osmo_gapk.c
+++ b/src/app_osmo_gapk.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <unistd.h>
#include <getopt.h>
+#include <talloc.h>
#include <sys/signal.h>
#include <sys/socket.h>
@@ -42,6 +43,8 @@
#include <osmocom/gapk/procqueue.h>
#include <osmocom/gapk/benchmark.h>
+/* The root talloc context of application */
+TALLOC_CTX *app_root_ctx;
struct gapk_options
{
@@ -62,6 +65,7 @@ struct gapk_options
const struct osmo_gapk_format_desc *fmt_out;
int benchmark;
+ int verbose;
};
struct gapk_state
@@ -281,6 +285,7 @@ parse_options(struct gapk_state *state, int argc, char *argv[])
case 'v':
log_parse_category_mask(osmo_stderr_target, "DAPP");
+ opt->verbose = 1;
break;
case 'h':
@@ -482,7 +487,7 @@ handle_headers(struct gapk_state *gs)
if (len && gs->in.file.fh) {
uint8_t *buf;
- buf = malloc(len);
+ buf = talloc_size(app_root_ctx, len);
if (!buf)
return -ENOMEM;
@@ -490,12 +495,12 @@ handle_headers(struct gapk_state *gs)
if ((rv != 1) ||
memcmp(buf, gs->opts.fmt_in->header, len))
{
- free(buf);
LOGP(DAPP, LOGL_ERROR, "Invalid header in input file");
+ talloc_free(buf);
return -EINVAL;
}
- free(buf);
+ talloc_free(buf);
}
/* Output file header (write it) */
@@ -670,6 +675,9 @@ static void app_shutdown(void)
/* Free memory taken by benchmark data */
osmo_gapk_bench_free();
+
+ if (gs->opts.verbose)
+ talloc_report_full(app_root_ctx, stderr);
}
static void signal_handler(int signal)
@@ -683,6 +691,10 @@ static void signal_handler(int signal)
exit(0);
}
break;
+ case SIGABRT:
+ case SIGUSR1:
+ case SIGUSR2:
+ talloc_report_full(app_root_ctx, stderr);
default:
break;
}
@@ -693,6 +705,10 @@ int main(int argc, char *argv[])
{
int rv;
+ /* Init talloc memory management system */
+ app_root_ctx = talloc_init("osmo-gapk root context");
+ osmo_gapk_set_talloc_ctx(app_root_ctx);
+
/* Init Osmocom logging framework */
osmo_init_logging(&gapk_log_info);
/* and GAPK logging wrapper */
@@ -747,6 +763,9 @@ int main(int argc, char *argv[])
}
signal(SIGINT, &signal_handler);
+ signal(SIGABRT, &signal_handler);
+ signal(SIGUSR1, &signal_handler);
+ signal(SIGUSR2, &signal_handler);
/* Run the processing queue */
LOGP(DAPP, LOGL_NOTICE, "Init complete, starting processing queue...\n");