]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/netdev: allow to register the same NetDev object with multiple names
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 9 Sep 2024 14:55:46 +0000 (23:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 10 Sep 2024 10:30:17 +0000 (19:30 +0900)
Preparation for later commits.

src/network/networkd-manager.c

index 4ebecaac5969f9d33c070a61200cd6fa6155e76c..2c2956f465084ad5fda031055592c136a0e20a20 100644 (file)
@@ -633,7 +633,11 @@ Manager* manager_free(Manager *m) {
         m->dhcp_pd_subnet_ids = set_free(m->dhcp_pd_subnet_ids);
         m->networks = ordered_hashmap_free_with_destructor(m->networks, network_unref);
 
-        m->netdevs = hashmap_free_with_destructor(m->netdevs, netdev_unref);
+        /* The same object may be registered with multiple names, and netdev_detach() may drop multiple
+         * entries. Hence, hashmap_free_with_destructor() cannot be used. */
+        for (NetDev *n; (n = hashmap_first(m->netdevs)); )
+                netdev_detach(n);
+        m->netdevs = hashmap_free(m->netdevs);
 
         m->tuntap_fds_by_name = hashmap_free(m->tuntap_fds_by_name);