]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: make etc_hosts_item_by_{address,name}_free() accept NULL
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Dec 2022 13:48:14 +0000 (22:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Dec 2022 11:29:12 +0000 (20:29 +0900)
src/resolve/resolved-etc-hosts.c

index a87989d1a38eaf9593415a260597674930feadf9..48d5f106e68e20551709fb02703a5fb936494a00 100644 (file)
 /* 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);