From 2af1f13c6f2c106d8ebb00772ca706f0e8e5d7f4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 13 Apr 2025 01:46:27 +0900 Subject: [PATCH] network/wireguard: use hash_ops with destructor for managing WireguardPeer --- src/network/netdev/wireguard.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index 5a58e1082cf..f497c2533ed 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -72,6 +72,11 @@ static WireguardPeer* wireguard_peer_free(WireguardPeer *peer) { DEFINE_SECTION_CLEANUP_FUNCTIONS(WireguardPeer, wireguard_peer_free); +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + wireguard_peer_hash_ops_by_section, + ConfigSection, config_section_hash_func, config_section_compare_func, + WireguardPeer, wireguard_peer_free); + static int wireguard_peer_new_static(Wireguard *w, const char *filename, unsigned section_line, WireguardPeer **ret) { _cleanup_(config_section_freep) ConfigSection *n = NULL; _cleanup_(wireguard_peer_freep) WireguardPeer *peer = NULL; @@ -104,7 +109,7 @@ static int wireguard_peer_new_static(Wireguard *w, const char *filename, unsigne LIST_PREPEND(peers, w->peers, peer); - r = hashmap_ensure_put(&w->peers_by_section, &config_section_hash_ops, peer->section, peer); + r = hashmap_ensure_put(&w->peers_by_section, &wireguard_peer_hash_ops_by_section, peer->section, peer); if (r < 0) return r; @@ -1077,7 +1082,7 @@ static void wireguard_done(NetDev *netdev) { explicit_bzero_safe(w->private_key, WG_KEY_LEN); free(w->private_key_file); - hashmap_free_with_destructor(w->peers_by_section, wireguard_peer_free); + hashmap_free(w->peers_by_section); set_free(w->routes); } -- 2.47.3