mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Merge branch 'ondrej/fix-leaked-memory-in-geoip_test.c' into 'master'
Fix leaked memory in geoip_test.c See merge request isc-projects/bind9!2154
This commit is contained in:
@@ -42,6 +42,9 @@ static dns_geoip_databases_t geoip;
|
||||
|
||||
static MMDB_s geoip_country, geoip_city, geoip_as, geoip_isp, geoip_domain;
|
||||
|
||||
static void load_geoip(const char *dir);
|
||||
static void close_geoip(void);
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
@@ -51,6 +54,9 @@ _setup(void **state) {
|
||||
result = dns_test_begin(NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -58,6 +64,8 @@ static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
close_geoip();
|
||||
|
||||
dns_test_end();
|
||||
|
||||
return (0);
|
||||
@@ -87,6 +95,15 @@ load_geoip(const char *dir) {
|
||||
geoip.domain = open_geoip2(dir, "GeoIP2-Domain.mmdb", &geoip_domain);
|
||||
}
|
||||
|
||||
static void
|
||||
close_geoip(void) {
|
||||
MMDB_close(&geoip_country);
|
||||
MMDB_close(&geoip_city);
|
||||
MMDB_close(&geoip_as);
|
||||
MMDB_close(&geoip_isp);
|
||||
MMDB_close(&geoip_domain);
|
||||
}
|
||||
|
||||
static bool
|
||||
do_lookup_string(const char *addr, dns_geoip_subtype_t subtype,
|
||||
const char *string)
|
||||
@@ -128,9 +145,6 @@ country(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.country == NULL) {
|
||||
skip();
|
||||
}
|
||||
@@ -157,9 +171,6 @@ country_v6(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.country == NULL) {
|
||||
skip();
|
||||
}
|
||||
@@ -180,9 +191,6 @@ city(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.city == NULL) {
|
||||
skip();
|
||||
}
|
||||
@@ -223,9 +231,6 @@ city_v6(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.city == NULL) {
|
||||
skip();
|
||||
}
|
||||
@@ -267,14 +272,10 @@ asnum(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.as == NULL) {
|
||||
skip();
|
||||
}
|
||||
|
||||
|
||||
match = do_lookup_string("10.53.0.3", dns_geoip_as_asnum, "AS100003");
|
||||
assert_true(match);
|
||||
}
|
||||
@@ -286,9 +287,6 @@ isp(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.isp == NULL) {
|
||||
skip();
|
||||
}
|
||||
@@ -305,9 +303,6 @@ org(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.as == NULL) {
|
||||
skip();
|
||||
}
|
||||
@@ -324,9 +319,6 @@ domain(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
/* Use databases from the geoip system test */
|
||||
load_geoip(TEST_GEOIP_DATA);
|
||||
|
||||
if (geoip.domain == NULL) {
|
||||
skip();
|
||||
}
|
||||
|
Reference in New Issue
Block a user