summaryrefslogtreecommitdiff
path: root/src/resolve
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-12-07 22:48:14 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-12-13 20:29:12 +0900
commitbb5c77305e53712aa5b039901c549266e7f2db11 (patch)
treeb11d033a8b8691f4ac63d3caa39cadc0261746f7 /src/resolve
parent133eedad2bbc6bf942411690a8bb7b27088d9730 (diff)
downloadsystemd-bb5c77305e53712aa5b039901c549266e7f2db11.tar.gz
resolve: make etc_hosts_item_by_{address,name}_free() accept NULL
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/resolved-etc-hosts.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c
index a87989d1a3..48d5f106e6 100644
--- a/src/resolve/resolved-etc-hosts.c
+++ b/src/resolve/resolved-etc-hosts.c
@@ -18,15 +18,21 @@
/* Recheck /etc/hosts at most once every 2s */
#define ETC_HOSTS_RECHECK_USEC (2*USEC_PER_SEC)
-static void etc_hosts_item_by_address_free(EtcHostsItemByAddress *item) {
+static EtcHostsItemByAddress *etc_hosts_item_by_address_free(EtcHostsItemByAddress *item) {
+ if (!item)
+ return NULL;
+
strv_free(item->names);
- free(item);
+ return mfree(item);
}
-static void etc_hosts_item_by_name_free(EtcHostsItemByName *item) {
+static EtcHostsItemByName *etc_hosts_item_by_name_free(EtcHostsItemByName *item) {
+ if (!item)
+ return NULL;
+
free(item->name);
free(item->addresses);
- free(item);
+ return mfree(item);
}
void etc_hosts_clear(EtcHosts *hosts) {
@@ -239,13 +245,8 @@ static void strip_localhost(EtcHosts *hosts) {
if (!in_order)
continue;
- STRV_FOREACH(i, item->names) {
- EtcHostsItemByName *n;
-
- n = hashmap_remove(hosts->by_name, *i);
- if (n)
- etc_hosts_item_by_name_free(n);
- }
+ STRV_FOREACH(i, item->names)
+ etc_hosts_item_by_name_free(hashmap_remove(hosts->by_name, *i));
assert_se(hashmap_remove(hosts->by_address, local_in_addrs + j) == item);
etc_hosts_item_by_address_free(item);