nic_router: fix leak on domain deinit

The deinitialization method of Domain used to rely on Domain::with_dhcp_server
in order to dissolve and destroy a present DHCP server. However, this method
skipped calling its functor argument also when there was a DHCP server but an
invalid one. This commt replaces the with_dhcp_server with a pointer null-check
in order to fix the leak.

Ref #4729
This commit is contained in:
Martin Stein 2024-05-17 14:36:24 +02:00 committed by Norman Feske
parent c96150bc70
commit f7f171e457

View File

@ -392,11 +392,12 @@ void Domain::deinit()
_tcp_rules.destroy_each(_alloc);
_udp_forward_rules.destroy_each(_alloc);
_tcp_forward_rules.destroy_each(_alloc);
with_dhcp_server([&] (Dhcp_server &dhcp_server) {
_dhcp_server_ptr = nullptr;
dhcp_server.with_dns_config_from([&] (Domain &domain) {
if (_dhcp_server_ptr) {
_dhcp_server_ptr->with_dns_config_from([&] (Domain &domain) {
domain.ip_config_dependents().remove(this); });
destroy(_alloc, &dhcp_server); });
_dhcp_server_ptr = nullptr;
destroy(_alloc, _dhcp_server_ptr);
}
}