From e34161832d936959640d5e5735dfa1ca7bccae13 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 5 Mar 2018 05:31:14 +0100 Subject: ctx cleanup: use non-NULL talloc ctx for osmo_init_logging2() Fix various sanitizer complaints about memory leaks using a sanitizer build with gcc (Debian 7.3.0-12) 7.3.0. Also fix deprecation warnings on osmo_init_logging(). Depends: I216837780e9405fdaec8059c63d10699c695b360 (libosmocore) Change-Id: I970c6f8a0e36a8b63e42349dbc92baff649e5cef --- src/ipaccess/ipaccess-config.c | 2 +- src/ipaccess/ipaccess-proxy.c | 2 +- src/osmo-bsc/osmo_bsc_main.c | 2 +- src/utils/bs11_config.c | 2 +- tests/abis/abis_test.c | 2 +- tests/bsc/bsc_test.c | 10 +++++++--- tests/channel/channel_test.c | 2 +- tests/gsm0408/gsm0408_test.c | 4 +++- tests/handover/handover_test.c | 12 +++++++++--- tests/nanobts_omlattr/nanobts_omlattr_test.c | 17 +++++++++++++---- tests/subscr/bsc_subscr_test.c | 5 +++-- 11 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/ipaccess/ipaccess-config.c b/src/ipaccess/ipaccess-config.c index 45cab8fbf..223606373 100644 --- a/src/ipaccess/ipaccess-config.c +++ b/src/ipaccess/ipaccess-config.c @@ -900,7 +900,7 @@ int main(int argc, char **argv) tall_ctx_config = talloc_named_const(NULL, 0, "ipaccess-config"); msgb_talloc_ctx_init(tall_ctx_config, 0); - osmo_init_logging(&log_info); + osmo_init_logging2(tall_ctx_config, &log_info); bts_model_nanobts_init(); printf("ipaccess-config (C) 2009-2010 by Harald Welte and others\n"); diff --git a/src/ipaccess/ipaccess-proxy.c b/src/ipaccess/ipaccess-proxy.c index 6a3af287c..aa5e7b499 100644 --- a/src/ipaccess/ipaccess-proxy.c +++ b/src/ipaccess/ipaccess-proxy.c @@ -1228,7 +1228,7 @@ int main(int argc, char **argv) tall_bsc_ctx = talloc_named_const(NULL, 1, "ipaccess-proxy"); msgb_talloc_ctx_init(tall_bsc_ctx, 0); - osmo_init_logging(&log_info); + osmo_init_logging2(tall_bsc_ctx, &log_info); log_parse_category_mask(osmo_stderr_target, "DLINP:DLMI"); handle_options(argc, argv); diff --git a/src/osmo-bsc/osmo_bsc_main.c b/src/osmo-bsc/osmo_bsc_main.c index 27c5640ea..89d0d02a5 100644 --- a/src/osmo-bsc/osmo_bsc_main.c +++ b/src/osmo-bsc/osmo_bsc_main.c @@ -414,7 +414,7 @@ int main(int argc, char **argv) tall_tqe_ctx = talloc_named_const(tall_bsc_ctx, 0, "subch_txq_entry"); tall_ctr_ctx = talloc_named_const(tall_bsc_ctx, 0, "counter"); - osmo_init_logging(&log_info); + osmo_init_logging2(tall_bsc_ctx, &log_info); osmo_stats_init(tall_bsc_ctx); /* Allocate global gsm_network struct */ diff --git a/src/utils/bs11_config.c b/src/utils/bs11_config.c index e7c833671..8d4de0152 100644 --- a/src/utils/bs11_config.c +++ b/src/utils/bs11_config.c @@ -911,7 +911,7 @@ int main(int argc, char **argv) tall_fle_ctx = talloc_named_const(tall_bs11cfg_ctx, 0, "bs11_file_list_entry"); msgb_talloc_ctx_init(tall_bs11cfg_ctx, 0); - osmo_init_logging(&log_info); + osmo_init_logging2(tall_bs11cfg_ctx, &log_info); handle_options(argc, argv); bts_model_bs11_init(); diff --git a/tests/abis/abis_test.c b/tests/abis/abis_test.c index 7deb0f00f..faf9ea533 100644 --- a/tests/abis/abis_test.c +++ b/tests/abis/abis_test.c @@ -175,7 +175,7 @@ static const struct log_info log_info = { int main(int argc, char **argv) { - osmo_init_logging(&log_info); + osmo_init_logging2(NULL, &log_info); test_sw_selection(); test_abis_nm_ipaccess_cgi(); diff --git a/tests/bsc/bsc_test.c b/tests/bsc/bsc_test.c index 744b9e1cb..106b08bc7 100644 --- a/tests/bsc/bsc_test.c +++ b/tests/bsc/bsc_test.c @@ -39,6 +39,8 @@ #include #include +void *ctx = NULL; + enum test { TEST_SCAN_TO_BTS, TEST_SCAN_TO_MSC, @@ -122,7 +124,7 @@ static void test_scan(void) { int i; - struct gsm_network *net = bsc_network_init(NULL); + struct gsm_network *net = bsc_network_init(ctx); struct gsm_bts *bts = gsm_bts_alloc(net, 0); struct bsc_msc_data *msc; struct gsm_subscriber_connection *conn; @@ -227,12 +229,14 @@ static const struct log_info log_info = { int main(int argc, char **argv) { - msgb_talloc_ctx_init(NULL, 0); - osmo_init_logging(&log_info); + ctx = talloc_named_const(NULL, 0, "bsc-test"); + msgb_talloc_ctx_init(ctx, 0); + osmo_init_logging2(ctx, &log_info); test_scan(); printf("Testing execution completed.\n"); + talloc_free(ctx); return 0; } diff --git a/tests/channel/channel_test.c b/tests/channel/channel_test.c index 78db1d4e3..e8f6cd921 100644 --- a/tests/channel/channel_test.c +++ b/tests/channel/channel_test.c @@ -98,7 +98,7 @@ static const struct log_info log_info = { int main(int argc, char **argv) { - osmo_init_logging(&log_info); + osmo_init_logging2(NULL, &log_info); test_dyn_ts_subslots(); test_bts_debug_print(); diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c index 67840f0e4..a934806b5 100644 --- a/tests/gsm0408/gsm0408_test.c +++ b/tests/gsm0408/gsm0408_test.c @@ -812,7 +812,9 @@ int main(int argc, char **argv) { struct gsm_network *net; - osmo_init_logging(&log_info); + tall_bsc_ctx = talloc_named_const(NULL, 0, "gsm0408_test"); + + osmo_init_logging2(tall_bsc_ctx, &log_info); log_set_log_level(osmo_stderr_target, LOGL_INFO); net = bsc_network_init(tall_bsc_ctx); diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c index 280861ca2..ab32a29a1 100644 --- a/tests/handover/handover_test.c +++ b/tests/handover/handover_test.c @@ -43,6 +43,8 @@ #include #include +void *ctx; + struct gsm_network *bsc_gsmnet; /* override, requires '-Wl,--wrap=mgcp_conn_modify'. @@ -213,7 +215,7 @@ static struct gsm_bts *create_bts(int arfcn) bts->codec.hr = 1; bts->codec.amr = 1; - rsl_link = talloc_zero(0, struct e1inp_sign_link); + rsl_link = talloc_zero(ctx, struct e1inp_sign_link); rsl_link->trx = bts->c0; bts->c0->rsl_link = rsl_link; @@ -1350,6 +1352,9 @@ int main(int argc, char **argv) int test_case_i; int last_test_i; + ctx = talloc_named_const(NULL, 0, "handover_test"); + msgb_talloc_ctx_init(ctx, 0); + test_case_i = argc > 1? atoi(argv[1]) : -1; last_test_i = ARRAY_SIZE(test_cases) - 1; @@ -1362,14 +1367,14 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - osmo_init_logging(&log_info); + osmo_init_logging2(ctx, &log_info); log_set_print_category(osmo_stderr_target, 1); log_set_print_category_hex(osmo_stderr_target, 0); log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME); /* Create a dummy network */ - bsc_gsmnet = bsc_network_init(NULL); + bsc_gsmnet = bsc_network_init(ctx); if (!bsc_gsmnet) exit(1); @@ -1676,6 +1681,7 @@ int main(int argc, char **argv) fprintf(stderr, "--------------------\n"); + talloc_free(ctx); return EXIT_SUCCESS; } diff --git a/tests/nanobts_omlattr/nanobts_omlattr_test.c b/tests/nanobts_omlattr/nanobts_omlattr_test.c index 663594cda..8e8626d13 100644 --- a/tests/nanobts_omlattr/nanobts_omlattr_test.c +++ b/tests/nanobts_omlattr/nanobts_omlattr_test.c @@ -199,11 +199,11 @@ int main(int argc, char **argv) struct gsm_network *net; struct gsm_bts_trx *trx; - osmo_init_logging(&log_info); - log_set_log_level(osmo_stderr_target, LOGL_INFO); - ctx = talloc_named_const(NULL, 0, "ctx"); + osmo_init_logging2(ctx, &log_info); + log_set_log_level(osmo_stderr_target, LOGL_INFO); + /* Allocate environmental structs (bts, net, trx) */ net = talloc_zero(ctx, struct gsm_network); INIT_LLIST_HEAD(&net->bts_list); @@ -282,7 +282,16 @@ int main(int argc, char **argv) talloc_free(net); talloc_free(trx); talloc_report_full(ctx, stderr); - OSMO_ASSERT(talloc_total_blocks(ctx) == 1); + /* Expecting something like: + * full talloc report on 'ctx' (total 813 bytes in 6 blocks) + * logging contains 813 bytes in 5 blocks (ref 0) 0x60b0000000a0 + * struct log_target contains 196 bytes in 2 blocks (ref 0) 0x6110000000a0 + * struct log_category contains 36 bytes in 1 blocks (ref 0) 0x60d0000003e0 + * struct log_info contains 616 bytes in 2 blocks (ref 0) 0x60d000000310 + * struct log_info_cat contains 576 bytes in 1 blocks (ref 0) 0x6170000000e0 + * That's the root ctx + 5x logging: */ + OSMO_ASSERT(talloc_total_blocks(ctx) == 6); + talloc_free(ctx); return 0; } diff --git a/tests/subscr/bsc_subscr_test.c b/tests/subscr/bsc_subscr_test.c index d15c1141d..3c94b8662 100644 --- a/tests/subscr/bsc_subscr_test.c +++ b/tests/subscr/bsc_subscr_test.c @@ -125,14 +125,15 @@ static const struct log_info log_info = { int main() { + void *ctx = talloc_named_const(NULL, 0, "bsc_subscr_test"); printf("Testing BSC subscriber core code.\n"); - osmo_init_logging(&log_info); + osmo_init_logging2(ctx, &log_info); log_set_print_filename(osmo_stderr_target, 0); log_set_print_timestamp(osmo_stderr_target, 0); log_set_use_color(osmo_stderr_target, 0); log_set_print_category(osmo_stderr_target, 1); - bsc_subscribers = talloc_zero(NULL, struct llist_head); + bsc_subscribers = talloc_zero(ctx, struct llist_head); INIT_LLIST_HEAD(bsc_subscribers); test_bsc_subscr(); -- cgit v1.2.3