mirror of https://gerrit.osmocom.org/gapk
osmo-gapk: use talloc for memory management
This commit is contained in:
parent
f23b747364
commit
5cabe1eeec
|
@ -26,6 +26,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <talloc.h>
|
||||||
|
|
||||||
#include <sys/signal.h>
|
#include <sys/signal.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -42,6 +43,8 @@
|
||||||
#include <osmocom/gapk/procqueue.h>
|
#include <osmocom/gapk/procqueue.h>
|
||||||
#include <osmocom/gapk/benchmark.h>
|
#include <osmocom/gapk/benchmark.h>
|
||||||
|
|
||||||
|
/* The root talloc context of application */
|
||||||
|
TALLOC_CTX *app_root_ctx;
|
||||||
|
|
||||||
struct gapk_options
|
struct gapk_options
|
||||||
{
|
{
|
||||||
|
@ -62,6 +65,7 @@ struct gapk_options
|
||||||
const struct osmo_gapk_format_desc *fmt_out;
|
const struct osmo_gapk_format_desc *fmt_out;
|
||||||
|
|
||||||
int benchmark;
|
int benchmark;
|
||||||
|
int verbose;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gapk_state
|
struct gapk_state
|
||||||
|
@ -281,6 +285,7 @@ parse_options(struct gapk_state *state, int argc, char *argv[])
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
log_parse_category_mask(osmo_stderr_target, "DAPP");
|
log_parse_category_mask(osmo_stderr_target, "DAPP");
|
||||||
|
opt->verbose = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -482,7 +487,7 @@ handle_headers(struct gapk_state *gs)
|
||||||
if (len && gs->in.file.fh) {
|
if (len && gs->in.file.fh) {
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
|
|
||||||
buf = malloc(len);
|
buf = talloc_size(app_root_ctx, len);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -490,12 +495,12 @@ handle_headers(struct gapk_state *gs)
|
||||||
if ((rv != 1) ||
|
if ((rv != 1) ||
|
||||||
memcmp(buf, gs->opts.fmt_in->header, len))
|
memcmp(buf, gs->opts.fmt_in->header, len))
|
||||||
{
|
{
|
||||||
free(buf);
|
|
||||||
LOGP(DAPP, LOGL_ERROR, "Invalid header in input file");
|
LOGP(DAPP, LOGL_ERROR, "Invalid header in input file");
|
||||||
|
talloc_free(buf);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
talloc_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output file header (write it) */
|
/* Output file header (write it) */
|
||||||
|
@ -670,6 +675,9 @@ static void app_shutdown(void)
|
||||||
|
|
||||||
/* Free memory taken by benchmark data */
|
/* Free memory taken by benchmark data */
|
||||||
osmo_gapk_bench_free();
|
osmo_gapk_bench_free();
|
||||||
|
|
||||||
|
if (gs->opts.verbose)
|
||||||
|
talloc_report_full(app_root_ctx, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void signal_handler(int signal)
|
static void signal_handler(int signal)
|
||||||
|
@ -683,6 +691,10 @@ static void signal_handler(int signal)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SIGABRT:
|
||||||
|
case SIGUSR1:
|
||||||
|
case SIGUSR2:
|
||||||
|
talloc_report_full(app_root_ctx, stderr);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -693,6 +705,10 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int rv;
|
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 */
|
/* Init Osmocom logging framework */
|
||||||
osmo_init_logging(&gapk_log_info);
|
osmo_init_logging(&gapk_log_info);
|
||||||
/* and GAPK logging wrapper */
|
/* and GAPK logging wrapper */
|
||||||
|
@ -747,6 +763,9 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGINT, &signal_handler);
|
signal(SIGINT, &signal_handler);
|
||||||
|
signal(SIGABRT, &signal_handler);
|
||||||
|
signal(SIGUSR1, &signal_handler);
|
||||||
|
signal(SIGUSR2, &signal_handler);
|
||||||
|
|
||||||
/* Run the processing queue */
|
/* Run the processing queue */
|
||||||
LOGP(DAPP, LOGL_NOTICE, "Init complete, starting processing queue...\n");
|
LOGP(DAPP, LOGL_NOTICE, "Init complete, starting processing queue...\n");
|
||||||
|
|
Loading…
Reference in New Issue