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
This commit is contained in:
Neels Hofmeyr 2018-04-16 00:57:10 +02:00
parent 20370aaf30
commit 8de6b8677d
9 changed files with 90 additions and 35 deletions

View File

@ -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");
osmo_init_logging(&info);
msgb_talloc_ctx_init(tall_bsc_ctx, 0);
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;
}

View File

@ -130,7 +130,8 @@ static struct log_info info = {
int main(int argc, char **argv)
{
osmo_init_logging(&info);
void *ctx = talloc_named_const(NULL, 0, "gprs_test");
osmo_init_logging2(ctx, &info);
test_8_4_2();
test_gprs_timer_enc_dec();

View File

@ -1762,8 +1762,9 @@ static struct log_info info = {
int main(int argc, char **argv)
{
osmo_init_logging(&info);
osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub");
void *log_ctx = talloc_named_const(osmo_gtphub_ctx, 0, "log");
osmo_init_logging2(log_ctx, &info);
test_nr_map_basic();
test_nr_map_wrap();
@ -1780,7 +1781,9 @@ int main(int argc, char **argv)
printf("Done\n");
talloc_report_full(osmo_gtphub_ctx, stderr);
talloc_free(log_ctx);
OSMO_ASSERT(talloc_total_blocks(osmo_gtphub_ctx) == 1);
talloc_free(osmo_gtphub_ctx);
return 0;
}

View File

@ -252,8 +252,9 @@ static struct log_info info = {
int main(int argc, char **argv)
{
msgb_talloc_ctx_init(NULL, 0);
osmo_init_logging(&info);
void *ctx = talloc_named_const(NULL, 0, "oap_client_test");
msgb_talloc_ctx_init(ctx, 0);
osmo_init_logging2(ctx, &info);
OSMO_ASSERT(osmo_stderr_target);
log_set_use_color(osmo_stderr_target, 0);

View File

@ -2444,8 +2444,8 @@ int main(int argc, char **argv)
void *osmo_sgsn_ctx;
void *msgb_ctx;
osmo_init_logging(&info);
osmo_sgsn_ctx = talloc_named_const(NULL, 0, "osmo_sgsn");
osmo_init_logging2(osmo_sgsn_ctx, &info);
tall_bsc_ctx = talloc_named_const(osmo_sgsn_ctx, 0, "bsc");
msgb_ctx = msgb_talloc_ctx_init(osmo_sgsn_ctx, 0);

View File

@ -250,17 +250,20 @@ static struct log_info info = {
int main(int argc, char **argv)
{
void *ctx;
osmo_init_logging(&info);
void *log_ctx;
ctx = talloc_named_const(NULL, 0, "slhc_ctx");
log_ctx = talloc_named_const(ctx, 0, "log");
osmo_init_logging2(log_ctx, &info);
test_slhc(ctx);
printf("Done\n");
talloc_report_full(ctx, stderr);
talloc_free(log_ctx);
OSMO_ASSERT(talloc_total_blocks(ctx) == 1);
talloc_free(ctx);
return 0;
}

View File

@ -261,10 +261,11 @@ static struct log_info info = {
int main(int argc, char **argv)
{
void *xid_ctx;
osmo_init_logging(&info);
void *log_ctx;
xid_ctx = talloc_named_const(NULL, 0, "xid_ctx");
log_ctx = talloc_named_const(xid_ctx, 0, "log");
osmo_init_logging2(log_ctx, &info);
test_xid_decode_realworld(xid_ctx);
test_xid_encode_decode(xid_ctx);
@ -272,7 +273,9 @@ int main(int argc, char **argv)
printf("Done\n");
talloc_report_full(xid_ctx, stderr);
talloc_free(log_ctx);
OSMO_ASSERT(talloc_total_blocks(xid_ctx) == 1);
talloc_free(xid_ctx);
return 0;
}

View File

@ -407,11 +407,12 @@ static struct log_info info = {
int main(int argc, char **argv)
{
void *v42bis_ctx;
void *log_ctx;
int i;
osmo_init_logging(&info);
v42bis_ctx = talloc_named_const(NULL, 0, "v42bis_ctx");
log_ctx = talloc_named_const(v42bis_ctx, 0, "log");
osmo_init_logging2(log_ctx, &info);
test_v42bis(v42bis_ctx);
@ -423,7 +424,9 @@ int main(int argc, char **argv)
printf("Done\n");
talloc_report_full(v42bis_ctx, stderr);
talloc_free(log_ctx);
OSMO_ASSERT(talloc_total_blocks(v42bis_ctx) == 1);
talloc_free(v42bis_ctx);
return 0;
}

View File

@ -142,17 +142,20 @@ static struct log_info info = {
int main(int argc, char **argv)
{
void *xid_ctx;
osmo_init_logging(&info);
void *log_ctx;
xid_ctx = talloc_named_const(NULL, 0, "xid_ctx");
log_ctx = talloc_named_const(xid_ctx, 0, "log");
osmo_init_logging2(log_ctx, &info);
test_xid_decode(xid_ctx);
test_xid_encode(xid_ctx);
printf("Done\n");
talloc_report_full(xid_ctx, stderr);
talloc_free(log_ctx);
OSMO_ASSERT(talloc_total_blocks(xid_ctx) == 1);
talloc_free(xid_ctx);
return 0;
}