chiark / gitweb /
dhcp-server: simplify dhcp server unref call
authorLennart Poettering <lennart@poettering.net>
Wed, 18 Jun 2014 16:54:52 +0000 (18:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 18 Jun 2014 22:00:24 +0000 (00:00 +0200)
No need to use HASHMAP_ITERATE when we destruct all entries anyway.

src/libsystemd-network/sd-dhcp-server.c

index d949502..5bdcf86 100644 (file)
@@ -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;
 }