aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests/bsc-nat
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-08-29 09:56:58 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-08-29 11:42:34 +0200
commit73ec6980d5207e5eec46659b61a3f9fe07c88162 (patch)
tree33d44ebb6bf2dbd4d316bca464ccb9769a938dcf /openbsc/tests/bsc-nat
parentdc16bdd3695fb62362106e8f15c65971cd794f4a (diff)
nat: Introduce a config free for the test and fix valgrind issues
The talloc_free on the nat lead to the freeing of the bsc_config which lead to freeing of the rate_ctr_group. The rate_ctr_group remained in a global list and the next creation of a bsc_config would access dead memory. Fix it. The free routine is only meant to be used by the test, for the real nat we would need to make sure that all connections and other state that refers to the cfg is removed/closed first. Fix various memleaks in the test while we are at it. There are still some to fix. ==7195== Invalid write of size 4 ==7195== at 0x4043171: rate_ctr_group_alloc (linuxlist.h:65) ==7195== by 0x804D893: bsc_config_alloc (bsc_nat_utils.c:174) ==7195== by 0x804B5D2: main (bsc_nat_test.c:954) ==7195== Address 0x4311cbc is 52 bytes inside a block of size 208 free'd ==7195== at 0x4029D28: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==7195== by 0x4048D98: _talloc_free (talloc.c:609) ==7195== by 0x4052806: talloc_free (talloc.c:578) ==7195== by 0x804B58A: main (bsc_nat_test.c:940)
Diffstat (limited to 'openbsc/tests/bsc-nat')
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index 6f517071a..245b081e1 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -419,7 +419,7 @@ static void test_contrack()
bsc_config_free(con->cfg);
- talloc_free(nat);
+ bsc_nat_free(nat);
msgb_free(msg);
}
@@ -453,7 +453,7 @@ static void test_paging(void)
abort();
}
- talloc_free(nat);
+ bsc_nat_free(nat);
}
static void test_mgcp_allocations(void)
@@ -577,7 +577,7 @@ static void test_mgcp_ass_tracking(void)
}
bsc_config_free(bsc->cfg);
- talloc_free(nat);
+ bsc_nat_free(nat);
}
/* test the code to find a given connection */
@@ -610,7 +610,7 @@ static void test_mgcp_find(void)
}
/* free everything */
- talloc_free(nat);
+ bsc_nat_free(nat);
}
static void test_mgcp_rewrite(void)
@@ -937,7 +937,7 @@ static void test_cr_filter()
}
msgb_free(msg);
- talloc_free(nat);
+ bsc_nat_free(nat);
}
static void test_dt_filter()
@@ -994,6 +994,9 @@ static void test_dt_filter()
memset(&cause, 0, sizeof(cause));
bsc_nat_filter_dt(bsc, msg, con, parsed, &cause);
}
+
+ msgb_free(msg);
+ bsc_nat_free(nat);
}
static void test_setup_rewrite()
@@ -1159,7 +1162,7 @@ static void test_setup_rewrite()
ARRAY_SIZE(cc_setup_national_again));
msgb_free(out);
bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, NULL);
- talloc_free(nat);
+ bsc_nat_free(nat);
}
static void test_setup_rewrite_prefix(void)
@@ -1208,7 +1211,7 @@ static void test_setup_rewrite_prefix(void)
msgb_free(out);
bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, NULL);
- talloc_free(nat);
+ bsc_nat_free(nat);
}
static void test_setup_rewrite_post(void)
@@ -1267,8 +1270,7 @@ static void test_setup_rewrite_post(void)
verify_msg(out, cc_setup_national, ARRAY_SIZE(cc_setup_national));
msgb_free(out);
- bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, NULL);
- talloc_free(nat);
+ bsc_nat_free(nat);
}
static void test_sms_smsc_rewrite()
@@ -1364,6 +1366,7 @@ static void test_sms_smsc_rewrite()
verify_msg(out, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
msgb_free(out);
+ bsc_nat_free(nat);
}
static void test_sms_number_rewrite(void)
@@ -1436,6 +1439,7 @@ static void test_sms_number_rewrite(void)
verify_msg(out, smsc_rewrite_num_patched_tp_srr,
ARRAY_SIZE(smsc_rewrite_num_patched_tp_srr));
msgb_free(out);
+ bsc_nat_free(nat);
}
static void test_barr_list_parsing(void)
@@ -1502,6 +1506,7 @@ static void test_barr_list_parsing(void)
entry->cm_reject_cause, entry->lu_reject_cause);
}
+ rc = bsc_nat_barr_adapt(NULL, &root, NULL);
}
static void test_nat_extract_lac()
@@ -1535,6 +1540,8 @@ static void test_nat_extract_lac()
/* verify the LAC */
OSMO_ASSERT(con.lac == 8210);
OSMO_ASSERT(con.ci == 50000);
+
+ bsc_nat_free(nat);
}
int main(int argc, char **argv)