2
0
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:
Ondřej Surý
2019-07-16 12:55:01 -04:00

View File

@@ -42,6 +42,9 @@ static dns_geoip_databases_t geoip;
static MMDB_s geoip_country, geoip_city, geoip_as, geoip_isp, geoip_domain; 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 static int
_setup(void **state) { _setup(void **state) {
isc_result_t result; isc_result_t result;
@@ -51,6 +54,9 @@ _setup(void **state) {
result = dns_test_begin(NULL, false); result = dns_test_begin(NULL, false);
assert_int_equal(result, ISC_R_SUCCESS); assert_int_equal(result, ISC_R_SUCCESS);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
return (0); return (0);
} }
@@ -58,6 +64,8 @@ static int
_teardown(void **state) { _teardown(void **state) {
UNUSED(state); UNUSED(state);
close_geoip();
dns_test_end(); dns_test_end();
return (0); return (0);
@@ -87,6 +95,15 @@ load_geoip(const char *dir) {
geoip.domain = open_geoip2(dir, "GeoIP2-Domain.mmdb", &geoip_domain); 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 static bool
do_lookup_string(const char *addr, dns_geoip_subtype_t subtype, do_lookup_string(const char *addr, dns_geoip_subtype_t subtype,
const char *string) const char *string)
@@ -128,9 +145,6 @@ country(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.country == NULL) { if (geoip.country == NULL) {
skip(); skip();
} }
@@ -157,9 +171,6 @@ country_v6(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.country == NULL) { if (geoip.country == NULL) {
skip(); skip();
} }
@@ -180,9 +191,6 @@ city(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.city == NULL) { if (geoip.city == NULL) {
skip(); skip();
} }
@@ -223,9 +231,6 @@ city_v6(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.city == NULL) { if (geoip.city == NULL) {
skip(); skip();
} }
@@ -267,14 +272,10 @@ asnum(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.as == NULL) { if (geoip.as == NULL) {
skip(); skip();
} }
match = do_lookup_string("10.53.0.3", dns_geoip_as_asnum, "AS100003"); match = do_lookup_string("10.53.0.3", dns_geoip_as_asnum, "AS100003");
assert_true(match); assert_true(match);
} }
@@ -286,9 +287,6 @@ isp(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.isp == NULL) { if (geoip.isp == NULL) {
skip(); skip();
} }
@@ -305,9 +303,6 @@ org(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.as == NULL) { if (geoip.as == NULL) {
skip(); skip();
} }
@@ -324,9 +319,6 @@ domain(void **state) {
UNUSED(state); UNUSED(state);
/* Use databases from the geoip system test */
load_geoip(TEST_GEOIP_DATA);
if (geoip.domain == NULL) { if (geoip.domain == NULL) {
skip(); skip();
} }