|
44 | 44 | #include "strv.h" |
45 | 45 | #include "tclass.h" |
46 | 46 |
|
| 47 | +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( |
| 48 | + stacked_netdevs_hash_ops, |
| 49 | + char, string_hash_func, string_compare_func, |
| 50 | + NetDev, netdev_unref); |
| 51 | + |
47 | 52 | static int network_resolve_netdev_one(Network *network, const char *name, NetDevKind kind, NetDev **ret) { |
48 | 53 | const char *kind_string; |
49 | 54 | NetDev *netdev; |
@@ -105,14 +110,14 @@ static int network_resolve_stacked_netdevs(Network *network) { |
105 | 110 | if (network_resolve_netdev_one(network, name, PTR_TO_INT(kind), &netdev) <= 0) |
106 | 111 | continue; |
107 | 112 |
|
108 | | - r = hashmap_ensure_put(&network->stacked_netdevs, &string_hash_ops, netdev->ifname, netdev); |
| 113 | + r = hashmap_ensure_put(&network->stacked_netdevs, &stacked_netdevs_hash_ops, netdev->ifname, netdev); |
109 | 114 | if (r == -ENOMEM) |
110 | 115 | return log_oom(); |
111 | 116 | if (r < 0) |
112 | 117 | log_warning_errno(r, "%s: Failed to add NetDev '%s' to network, ignoring: %m", |
113 | 118 | network->filename, (const char *) name); |
114 | 119 |
|
115 | | - netdev = NULL; |
| 120 | + TAKE_PTR(netdev); |
116 | 121 | } |
117 | 122 |
|
118 | 123 | return 0; |
@@ -825,7 +830,7 @@ static Network *network_free(Network *network) { |
825 | 830 | netdev_unref(network->bridge); |
826 | 831 | netdev_unref(network->bond); |
827 | 832 | netdev_unref(network->vrf); |
828 | | - hashmap_free_with_destructor(network->stacked_netdevs, netdev_unref); |
| 833 | + hashmap_free(network->stacked_netdevs); |
829 | 834 |
|
830 | 835 | /* static configs */ |
831 | 836 | set_free_free(network->ipv6_proxy_ndp_addresses); |
|
0 commit comments