Skip to content

Commit 5c6e6f5

Browse files
committed
network/dhcp-server: use hash_ops with destructor for static lease
1 parent 10d7864 commit 5c6e6f5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/network/networkd-dhcp-server-static-lease.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include "networkd-network.h"
88
#include "networkd-util.h"
99

10-
DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
11-
12-
DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
10+
static DHCPStaticLease* dhcp_static_lease_free(DHCPStaticLease *static_lease) {
1311
if (!static_lease)
1412
return NULL;
1513

@@ -21,6 +19,13 @@ DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
2119
return mfree(static_lease);
2220
}
2321

22+
DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
23+
24+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
25+
static_lease_hash_ops_by_section,
26+
ConfigSection, config_section_hash_func, config_section_compare_func,
27+
DHCPStaticLease, dhcp_static_lease_free);
28+
2429
static int dhcp_static_lease_new(DHCPStaticLease **ret) {
2530
DHCPStaticLease *p;
2631

@@ -60,7 +65,8 @@ static int lease_new_static(Network *network, const char *filename, unsigned sec
6065

6166
static_lease->network = network;
6267
static_lease->section = TAKE_PTR(n);
63-
r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &config_section_hash_ops, static_lease->section, static_lease);
68+
69+
r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &static_lease_hash_ops_by_section, static_lease->section, static_lease);
6470
if (r < 0)
6571
return r;
6672

src/network/networkd-dhcp-server-static-lease.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ typedef struct DHCPStaticLease {
1919
size_t client_id_size;
2020
} DHCPStaticLease;
2121

22-
DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *lease);
2322
void network_drop_invalid_static_leases(Network *network);
2423

2524
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_static_lease_address);

src/network/networkd-network.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ static Network *network_free(Network *network) {
835835
hashmap_free(network->route_prefixes_by_section);
836836
hashmap_free(network->pref64_prefixes_by_section);
837837
hashmap_free(network->rules_by_section);
838-
hashmap_free_with_destructor(network->dhcp_static_leases_by_section, dhcp_static_lease_free);
838+
hashmap_free(network->dhcp_static_leases_by_section);
839839
ordered_hashmap_free(network->sr_iov_by_section);
840840
hashmap_free(network->qdiscs_by_section);
841841
hashmap_free(network->tclasses_by_section);

0 commit comments

Comments
 (0)