diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-03-05 05:31:14 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-03-28 19:24:34 +0200 |
commit | e34161832d936959640d5e5735dfa1ca7bccae13 (patch) | |
tree | ec2853807f0e1ae88607eea6e68e3edd0e51ad70 /tests | |
parent | 68c76e9036538d51232c61ce8c5c28e4035456ac (diff) |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/abis/abis_test.c | 2 | ||||
-rw-r--r-- | tests/bsc/bsc_test.c | 10 | ||||
-rw-r--r-- | tests/channel/channel_test.c | 2 | ||||
-rw-r--r-- | tests/gsm0408/gsm0408_test.c | 4 | ||||
-rw-r--r-- | tests/handover/handover_test.c | 12 | ||||
-rw-r--r-- | tests/nanobts_omlattr/nanobts_omlattr_test.c | 17 | ||||
-rw-r--r-- | tests/subscr/bsc_subscr_test.c | 5 |
7 files changed, 37 insertions, 15 deletions
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 <stdio.h> #include <search.h> +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 <osmocom/bsc/osmo_bsc.h> #include <osmocom/bsc/bsc_subscr_conn_fsm.h> +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(); |