Skip to content

Commit 919aeb6

Browse files
committed
network/network: use hash_ops with destructor for managing stacked netdevs
1 parent e260393 commit 919aeb6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/network/networkd-network.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
#include "strv.h"
4545
#include "tclass.h"
4646

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+
4752
static int network_resolve_netdev_one(Network *network, const char *name, NetDevKind kind, NetDev **ret) {
4853
const char *kind_string;
4954
NetDev *netdev;
@@ -105,14 +110,14 @@ static int network_resolve_stacked_netdevs(Network *network) {
105110
if (network_resolve_netdev_one(network, name, PTR_TO_INT(kind), &netdev) <= 0)
106111
continue;
107112

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);
109114
if (r == -ENOMEM)
110115
return log_oom();
111116
if (r < 0)
112117
log_warning_errno(r, "%s: Failed to add NetDev '%s' to network, ignoring: %m",
113118
network->filename, (const char *) name);
114119

115-
netdev = NULL;
120+
TAKE_PTR(netdev);
116121
}
117122

118123
return 0;
@@ -825,7 +830,7 @@ static Network *network_free(Network *network) {
825830
netdev_unref(network->bridge);
826831
netdev_unref(network->bond);
827832
netdev_unref(network->vrf);
828-
hashmap_free_with_destructor(network->stacked_netdevs, netdev_unref);
833+
hashmap_free(network->stacked_netdevs);
829834

830835
/* static configs */
831836
set_free_free(network->ipv6_proxy_ndp_addresses);

0 commit comments

Comments
 (0)