From 5c6e6f5ad17ef7e9100ca8a97cdf4a12c9644e6a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 13 Apr 2025 02:54:06 +0900 Subject: [PATCH] network/dhcp-server: use hash_ops with destructor for static lease --- src/network/networkd-dhcp-server-static-lease.c | 14 ++++++++++---- src/network/networkd-dhcp-server-static-lease.h | 1 - src/network/networkd-network.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/network/networkd-dhcp-server-static-lease.c b/src/network/networkd-dhcp-server-static-lease.c index 8e7eec64d17..b8c7e4dde8b 100644 --- a/src/network/networkd-dhcp-server-static-lease.c +++ b/src/network/networkd-dhcp-server-static-lease.c @@ -7,9 +7,7 @@ #include "networkd-network.h" #include "networkd-util.h" -DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free); - -DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) { +static DHCPStaticLease* dhcp_static_lease_free(DHCPStaticLease *static_lease) { if (!static_lease) return NULL; @@ -21,6 +19,13 @@ DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) { return mfree(static_lease); } +DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free); + +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + static_lease_hash_ops_by_section, + ConfigSection, config_section_hash_func, config_section_compare_func, + DHCPStaticLease, dhcp_static_lease_free); + static int dhcp_static_lease_new(DHCPStaticLease **ret) { DHCPStaticLease *p; @@ -60,7 +65,8 @@ static int lease_new_static(Network *network, const char *filename, unsigned sec static_lease->network = network; static_lease->section = TAKE_PTR(n); - r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &config_section_hash_ops, static_lease->section, static_lease); + + r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &static_lease_hash_ops_by_section, static_lease->section, static_lease); if (r < 0) return r; diff --git a/src/network/networkd-dhcp-server-static-lease.h b/src/network/networkd-dhcp-server-static-lease.h index 9b8e78b90d8..fe8e249d5a7 100644 --- a/src/network/networkd-dhcp-server-static-lease.h +++ b/src/network/networkd-dhcp-server-static-lease.h @@ -19,7 +19,6 @@ typedef struct DHCPStaticLease { size_t client_id_size; } DHCPStaticLease; -DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *lease); void network_drop_invalid_static_leases(Network *network); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_static_lease_address); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 3ae87e939a7..d036e99ec3c 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -835,7 +835,7 @@ static Network *network_free(Network *network) { hashmap_free(network->route_prefixes_by_section); hashmap_free(network->pref64_prefixes_by_section); hashmap_free(network->rules_by_section); - hashmap_free_with_destructor(network->dhcp_static_leases_by_section, dhcp_static_lease_free); + hashmap_free(network->dhcp_static_leases_by_section); ordered_hashmap_free(network->sr_iov_by_section); hashmap_free(network->qdiscs_by_section); hashmap_free(network->tclasses_by_section); -- 2.47.3