Harald Welte has submitted this change and it was merged.

Change subject: ctx cleanup: use non-NULL talloc ctx for osmo_init_logging2()
......................................................................


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
---
M src/ipaccess/ipaccess-config.c
M src/ipaccess/ipaccess-proxy.c
M src/osmo-bsc/osmo_bsc_main.c
M src/utils/bs11_config.c
M tests/abis/abis_test.c
M tests/bsc/bsc_test.c
M tests/channel/channel_test.c
M tests/gsm0408/gsm0408_test.c
M tests/handover/handover_test.c
M tests/nanobts_omlattr/nanobts_omlattr_test.c
M tests/subscr/bsc_subscr_test.c
11 files changed, 41 insertions(+), 19 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/ipaccess/ipaccess-config.c b/src/ipaccess/ipaccess-config.c
index 45cab8f..2236063 100644
--- a/src/ipaccess/ipaccess-config.c
+++ b/src/ipaccess/ipaccess-config.c
@@ -900,7 +900,7 @@
        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 6a3af28..aa5e7b4 100644
--- a/src/ipaccess/ipaccess-proxy.c
+++ b/src/ipaccess/ipaccess-proxy.c
@@ -1228,7 +1228,7 @@
        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 27c5640..89d0d02 100644
--- a/src/osmo-bsc/osmo_bsc_main.c
+++ b/src/osmo-bsc/osmo_bsc_main.c
@@ -414,7 +414,7 @@
        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 e7c8336..8d4de01 100644
--- a/src/utils/bs11_config.c
+++ b/src/utils/bs11_config.c
@@ -911,7 +911,7 @@
        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 7deb0f0..faf9ea5 100644
--- a/tests/abis/abis_test.c
+++ b/tests/abis/abis_test.c
@@ -175,7 +175,7 @@
 
 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 744b9e1..106b08b 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 @@
 {
        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 @@
 
 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 78db1d4..e8f6cd9 100644
--- a/tests/channel/channel_test.c
+++ b/tests/channel/channel_test.c
@@ -98,7 +98,7 @@
 
 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 67840f0..a934806 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -812,7 +812,9 @@
 {
        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 280861c..ab32a29 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 @@
        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 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 @@
                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 @@
 
        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 663594c..8e8626d 100644
--- a/tests/nanobts_omlattr/nanobts_omlattr_test.c
+++ b/tests/nanobts_omlattr/nanobts_omlattr_test.c
@@ -199,10 +199,10 @@
        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);
@@ -282,7 +282,16 @@
        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 d15c114..3c94b86 100644
--- a/tests/subscr/bsc_subscr_test.c
+++ b/tests/subscr/bsc_subscr_test.c
@@ -125,14 +125,15 @@
 
 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();

-- 
To view, visit https://gerrit.osmocom.org/7565
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I970c6f8a0e36a8b63e42349dbc92baff649e5cef
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder

Reply via email to