diff options
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/fuzz-etc-hosts.c | 2 | ||||
-rw-r--r-- | src/resolve/resolved-etc-hosts.c | 10 | ||||
-rw-r--r-- | src/resolve/resolved-etc-hosts.h | 2 | ||||
-rw-r--r-- | src/resolve/test-resolved-etc-hosts.c | 6 |
4 files changed, 11 insertions, 9 deletions
diff --git a/src/resolve/fuzz-etc-hosts.c b/src/resolve/fuzz-etc-hosts.c index 050c85dab4..bd6d0a8d5d 100644 --- a/src/resolve/fuzz-etc-hosts.c +++ b/src/resolve/fuzz-etc-hosts.c @@ -6,7 +6,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_fclose_ FILE *f = NULL; - _cleanup_(etc_hosts_free) EtcHosts h = {}; + _cleanup_(etc_hosts_clear) EtcHosts h = {}; if (!getenv("SYSTEMD_LOG_LEVEL")) log_set_max_level(LOG_CRIT); diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 8a58db4a21..5dff0d96ba 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -29,14 +29,16 @@ static void etc_hosts_item_by_name_free(EtcHostsItemByName *item) { free(item); } -void etc_hosts_free(EtcHosts *hosts) { +void etc_hosts_clear(EtcHosts *hosts) { + assert(hosts); + hosts->by_address = hashmap_free_with_destructor(hosts->by_address, etc_hosts_item_free); hosts->by_name = hashmap_free_with_destructor(hosts->by_name, etc_hosts_item_by_name_free); hosts->no_address = set_free_free(hosts->no_address); } void manager_etc_hosts_flush(Manager *m) { - etc_hosts_free(&m->etc_hosts); + etc_hosts_clear(&m->etc_hosts); m->etc_hosts_stat = (struct stat) {}; } @@ -251,7 +253,7 @@ static void strip_localhost(EtcHosts *hosts) { } int etc_hosts_parse(EtcHosts *hosts, FILE *f) { - _cleanup_(etc_hosts_free) EtcHosts t = {}; + _cleanup_(etc_hosts_clear) EtcHosts t = {}; unsigned nr = 0; int r; @@ -282,7 +284,7 @@ int etc_hosts_parse(EtcHosts *hosts, FILE *f) { strip_localhost(&t); - etc_hosts_free(hosts); + etc_hosts_clear(hosts); *hosts = t; t = (EtcHosts) {}; /* prevent cleanup */ return 0; diff --git a/src/resolve/resolved-etc-hosts.h b/src/resolve/resolved-etc-hosts.h index df66e714da..44eaf2b347 100644 --- a/src/resolve/resolved-etc-hosts.h +++ b/src/resolve/resolved-etc-hosts.h @@ -20,7 +20,7 @@ typedef struct EtcHostsItemByName { } EtcHostsItemByName; int etc_hosts_parse(EtcHosts *hosts, FILE *f); -void etc_hosts_free(EtcHosts *hosts); +void etc_hosts_clear(EtcHosts *hosts); void manager_etc_hosts_flush(Manager *m); int manager_etc_hosts_lookup(Manager *m, DnsQuestion* q, DnsAnswer **answer); diff --git a/src/resolve/test-resolved-etc-hosts.c b/src/resolve/test-resolved-etc-hosts.c index d6cd184b5e..a0f712cbb6 100644 --- a/src/resolve/test-resolved-etc-hosts.c +++ b/src/resolve/test-resolved-etc-hosts.c @@ -23,7 +23,7 @@ TEST(parse_etc_hosts_system) { return; } - _cleanup_(etc_hosts_free) EtcHosts hosts = {}; + _cleanup_(etc_hosts_clear) EtcHosts hosts = {}; assert_se(etc_hosts_parse(&hosts, f) == 0); } @@ -67,7 +67,7 @@ TEST(parse_etc_hosts) { assert_se(fflush_and_check(f) >= 0); rewind(f); - _cleanup_(etc_hosts_free) EtcHosts hosts = {}; + _cleanup_(etc_hosts_clear) EtcHosts hosts = {}; assert_se(etc_hosts_parse(&hosts, f) == 0); EtcHostsItemByName *bn; @@ -124,7 +124,7 @@ TEST(parse_etc_hosts) { } static void test_parse_file_one(const char *fname) { - _cleanup_(etc_hosts_free) EtcHosts hosts = {}; + _cleanup_(etc_hosts_clear) EtcHosts hosts = {}; _cleanup_fclose_ FILE *f; log_info("/* %s(\"%s\") */", __func__, fname); |