network/dhcp-server: use hash_ops with destructor for static lease
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user