diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-04-16 00:57:10 +0200 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-04-16 01:03:48 +0200 |
commit | 5bd340eb5a176af428847949268869d71de8802c (patch) | |
tree | 7b65a93dc9a2e4309f04ca7921535b9b598c1930 /tests/gbproxy | |
parent | 69e356be93c420b5e2f8b96fbc89ef889cbcfe53 (diff) |
use osmo_init_logging2(), fix regression test memleaks
Particularly gbproxy_test.c had various mem leaks, which (will) show up with
gcc (Debian 7.3.0-15) 7.3.0 address sanitizer. Fix those leaks to verify that
we don't have memleaks in the production code.
Change-Id: Ia4204c8b3d895b42c103edecb61b99d3d22bd36f
Diffstat (limited to 'tests/gbproxy')
-rw-r--r-- | tests/gbproxy/gbproxy_test.c | 82 |
1 files changed, 60 insertions, 22 deletions
diff --git a/tests/gbproxy/gbproxy_test.c b/tests/gbproxy/gbproxy_test.c index 8edb17148..f9a1c6bf8 100644 --- a/tests/gbproxy/gbproxy_test.c +++ b/tests/gbproxy/gbproxy_test.c @@ -47,7 +47,7 @@ #define MATCH_ANY (-1) -void *tall_bsc_ctx; +void *tall_bsc_ctx = NULL; struct gbproxy_config gbcfg = {0}; @@ -1329,7 +1329,7 @@ static void gprs_dump_nsi(struct gprs_ns_inst *nsi) static void test_gbproxy() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[4] = {{0},}; struct sockaddr_in sgsn_peer= {0}; @@ -1497,7 +1497,7 @@ static void test_gbproxy() static void test_gbproxy_ident_changes() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; uint16_t nsei[2] = {0x1000, 0x2000}; @@ -1629,7 +1629,7 @@ static void test_gbproxy_ident_changes() static void test_gbproxy_ra_patching() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; struct gprs_ra_id rai_bss = @@ -1657,7 +1657,7 @@ static void test_gbproxy_ra_patching() gbcfg.nsi = bssgp_nsi; gbcfg.nsip_sgsn_nsei = SGSN_NSEI; gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; - gbcfg.core_apn = talloc_zero_size(NULL, 100); + gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); gbcfg.patch_ptmsi = 0; @@ -1960,6 +1960,9 @@ static void test_gbproxy_ra_patching() OSMO_ASSERT(!expect_msg()); received_messages = NULL; + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbproxy_clear_patch_filter(&gbcfg.matches[GBPROX_MATCH_PATCHING]); gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); @@ -1968,7 +1971,7 @@ static void test_gbproxy_ra_patching() static void test_gbproxy_ptmsi_assignment() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; struct gprs_ra_id rai_bss = @@ -1997,7 +2000,7 @@ static void test_gbproxy_ptmsi_assignment() gbcfg.nsi = bssgp_nsi; gbcfg.nsip_sgsn_nsei = SGSN_NSEI; gbcfg.core_plmn = (struct osmo_plmn_id){}; - gbcfg.core_apn = talloc_zero_size(NULL, 100); + gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); gbcfg.patch_ptmsi = 0; @@ -2172,6 +2175,9 @@ static void test_gbproxy_ptmsi_assignment() dump_global(stdout, 0); + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); nsi = NULL; @@ -2181,7 +2187,7 @@ static void test_gbproxy_ptmsi_assignment() static void test_gbproxy_ptmsi_patching() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; struct gprs_ra_id rai_bss = @@ -2230,7 +2236,7 @@ static void test_gbproxy_ptmsi_patching() gbcfg.nsi = bssgp_nsi; gbcfg.nsip_sgsn_nsei = SGSN_NSEI; gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; - gbcfg.core_apn = talloc_zero_size(NULL, 100); + gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); gbcfg.patch_ptmsi = 1; @@ -2508,6 +2514,9 @@ static void test_gbproxy_ptmsi_patching() dump_global(stdout, 0); + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); nsi = NULL; @@ -2517,7 +2526,7 @@ static void test_gbproxy_ptmsi_patching() static void test_gbproxy_ptmsi_patching_bad_cases() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; struct gprs_ra_id rai_bss = @@ -2548,7 +2557,7 @@ static void test_gbproxy_ptmsi_patching_bad_cases() gbcfg.nsi = bssgp_nsi; gbcfg.nsip_sgsn_nsei = SGSN_NSEI; gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; - gbcfg.core_apn = talloc_zero_size(NULL, 100); + gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); gbcfg.patch_ptmsi = 1; @@ -2686,6 +2695,9 @@ static void test_gbproxy_ptmsi_patching_bad_cases() dump_global(stdout, 0); + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); nsi = NULL; @@ -2696,7 +2708,7 @@ static void test_gbproxy_ptmsi_patching_bad_cases() static void test_gbproxy_imsi_acquisition() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; struct gprs_ra_id rai_bss = @@ -2731,7 +2743,7 @@ static void test_gbproxy_imsi_acquisition() gbcfg.nsi = bssgp_nsi; gbcfg.nsip_sgsn_nsei = SGSN_NSEI; gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; - gbcfg.core_apn = talloc_zero_size(NULL, 100); + gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); gbcfg.patch_ptmsi = 1; gbcfg.acquire_imsi = 1; @@ -2997,6 +3009,9 @@ static void test_gbproxy_imsi_acquisition() dump_global(stdout, 0); + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); nsi = NULL; @@ -3006,7 +3021,7 @@ static void test_gbproxy_imsi_acquisition() static void test_gbproxy_secondary_sgsn() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer[2]= {{0},}; struct gprs_ra_id rai_bss = @@ -3056,7 +3071,7 @@ static void test_gbproxy_secondary_sgsn() gbcfg.nsi = bssgp_nsi; gbcfg.nsip_sgsn_nsei = SGSN_NSEI; gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 }; - gbcfg.core_apn = talloc_zero_size(NULL, 100); + gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); gbcfg.patch_ptmsi = 1; gbcfg.acquire_imsi = 1; @@ -3497,6 +3512,9 @@ static void test_gbproxy_secondary_sgsn() dump_global(stdout, 0); + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbproxy_clear_patch_filter(&gbcfg.matches[GBPROX_MATCH_ROUTING]); gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); @@ -3507,7 +3525,7 @@ static void test_gbproxy_secondary_sgsn() static void test_gbproxy_keep_info() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; struct gprs_ra_id rai_bss = @@ -4440,6 +4458,9 @@ static void test_gbproxy_keep_info() dump_global(stdout, 0); + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); nsi = NULL; @@ -4728,6 +4749,8 @@ static void test_gbproxy_tlli_expire(void) } gbproxy_clear_patch_filter(&cfg.matches[GBPROX_MATCH_PATCHING]); gbprox_reset(&cfg); + /* gbprox_reset() frees the rate_ctr, but re-allocates it again. */ + rate_ctr_group_free(cfg.ctrg); cleanup_test(); } @@ -4810,7 +4833,7 @@ static void test_gbproxy_imsi_matching(void) static void test_gbproxy_stored_messages() { - struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); + struct gprs_ns_inst *nsi = gprs_ns_instantiate(gprs_ns_callback, tall_bsc_ctx); struct sockaddr_in bss_peer[1] = {{0},}; struct sockaddr_in sgsn_peer= {0}; struct gprs_ra_id rai_bss = @@ -4834,7 +4857,7 @@ static void test_gbproxy_stored_messages() gbcfg.nsi = bssgp_nsi; gbcfg.nsip_sgsn_nsei = SGSN_NSEI; gbcfg.core_plmn = (struct osmo_plmn_id){}; - gbcfg.core_apn = talloc_zero_size(NULL, 100); + gbcfg.core_apn = talloc_zero_size(tall_bsc_ctx, 100); gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar"); gbcfg.patch_ptmsi = 0; gbcfg.acquire_imsi = 1; @@ -4894,6 +4917,9 @@ static void test_gbproxy_stored_messages() dump_global(stdout, 0); + talloc_free(gbcfg.core_apn); + gbcfg.core_apn = NULL; + gbprox_reset(&gbcfg); gprs_ns_destroy(nsi); nsi = NULL; @@ -4926,9 +4952,13 @@ static struct log_info info = { int main(int argc, char **argv) { - msgb_talloc_ctx_init(NULL, 0); + talloc_enable_leak_report(); + tall_bsc_ctx = talloc_named_const(NULL, 0, "gbproxy_test"); + void *log_ctx = talloc_named_const(tall_bsc_ctx, 0, "log"); + + msgb_talloc_ctx_init(tall_bsc_ctx, 0); - osmo_init_logging(&info); + osmo_init_logging2(log_ctx, &info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); osmo_signal_register_handler(SS_L_NS, &test_signal, &gbcfg); @@ -4937,7 +4967,7 @@ int main(int argc, char **argv) log_set_log_level(osmo_stderr_target, LOGL_DEBUG); log_set_all_filter(osmo_stderr_target, 1); - rate_ctr_init(NULL); + rate_ctr_init(tall_bsc_ctx); setlinebuf(stdout); @@ -4955,7 +4985,15 @@ int main(int argc, char **argv) test_gbproxy_keep_info(); test_gbproxy_tlli_expire(); test_gbproxy_stored_messages(); + gbprox_reset(&gbcfg); + /* gbprox_reset() frees the rate_ctr, but re-allocates it again. */ + rate_ctr_group_free(gbcfg.ctrg); printf("===== GbProxy test END\n\n"); - exit(EXIT_SUCCESS); + talloc_free(log_ctx); + /* expecting root and msgb ctx, empty */ + OSMO_ASSERT(talloc_total_blocks(tall_bsc_ctx) == 2); + talloc_free(tall_bsc_ctx); + + return 0; } |