resolve: rename etc_hosts_free() -> etc_hosts_clear()

This commit is contained in:
Yu Watanabe 2022-12-07 22:30:45 +09:00
parent 10b89c59dc
commit 0f7bdf3503
4 changed files with 11 additions and 9 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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);