diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-06-18 18:54:52 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-06-19 00:00:24 +0200 |
commit | 3bdace9bf779ce051f00c14914b35c3a26164aa9 (patch) | |
tree | f915da7f5c62686948563389e0f62db5e9241bc6 /src/libsystemd-network | |
parent | df9db010def086cefa1225d0ac071cba96d9a610 (diff) |
dhcp-server: simplify dhcp server unref call
No need to use HASHMAP_ITERATE when we destruct all entries anyway.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r-- | src/libsystemd-network/sd-dhcp-server.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index d9495024ab..5bdcf860bc 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -109,25 +109,26 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DHCPLease*, dhcp_lease_free); #define _cleanup_dhcp_lease_free_ _cleanup_(dhcp_lease_freep) sd_dhcp_server *sd_dhcp_server_unref(sd_dhcp_server *server) { - if (server && REFCNT_DEC(server->n_ref) <= 0) { - DHCPLease *lease; - Iterator i; + DHCPLease *lease; - log_dhcp_server(server, "UNREF"); + if (!server) + return NULL; - sd_dhcp_server_stop(server); + if (REFCNT_DEC(server->n_ref) > 0) + return NULL; - sd_event_unref(server->event); + log_dhcp_server(server, "UNREF"); - HASHMAP_FOREACH(lease, server->leases_by_client_id, i) { - hashmap_remove(server->leases_by_client_id, lease); - dhcp_lease_free(lease); - } + sd_dhcp_server_stop(server); - hashmap_free(server->leases_by_client_id); - free(server->bound_leases); - free(server); - } + sd_event_unref(server->event); + + while ((lease = hashmap_steal_first(server->leases_by_client_id))) + dhcp_lease_free(lease); + hashmap_free(server->leases_by_client_id); + + free(server->bound_leases); + free(server); return NULL; } |