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)
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index 6f51707..245b081 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -419,7 +419,7 @@
 
 
 	bsc_config_free(con->cfg);
-	talloc_free(nat);
+	bsc_nat_free(nat);
 	msgb_free(msg);
 }
 
@@ -453,7 +453,7 @@
 		abort();
 	}
 
-	talloc_free(nat);
+	bsc_nat_free(nat);
 }
 
 static void test_mgcp_allocations(void)
@@ -577,7 +577,7 @@
 	}
 
 	bsc_config_free(bsc->cfg);
-	talloc_free(nat);
+	bsc_nat_free(nat);
 }
 
 /* test the code to find a given connection */
@@ -610,7 +610,7 @@
 	}
 
 	/* free everything */
-	talloc_free(nat);
+	bsc_nat_free(nat);
 }
 
 static void test_mgcp_rewrite(void)
@@ -937,7 +937,7 @@
 	}
 
 	msgb_free(msg);
-	talloc_free(nat);
+	bsc_nat_free(nat);
 }
 
 static void test_dt_filter()
@@ -994,6 +994,9 @@
 		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 @@
 			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 @@
 	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 @@
 	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 @@
 
 	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 @@
 	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 @@
 			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 @@
 	/* verify the LAC */
 	OSMO_ASSERT(con.lac == 8210);
 	OSMO_ASSERT(con.ci == 50000);
+
+	bsc_nat_free(nat);
 }
 
 int main(int argc, char **argv)