diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-11-28 12:35:49 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-11-28 21:30:30 +0100 |
commit | 224b0e7ad0116579f830b7dd387b97c3facb65d9 (patch) | |
tree | d769049843011ec955d86af31e2f0d62c4521f38 /src/resolve | |
parent | Use hashmap_free_free where appropriate (diff) | |
download | systemd-224b0e7ad0116579f830b7dd387b97c3facb65d9.tar.xz systemd-224b0e7ad0116579f830b7dd387b97c3facb65d9.zip |
Add set/hashmap helpers for non-trivial freeing and use where straighforward
A macro is needed because otherwise we couldn't ensure type safety.
Some simple tests are included.
No functional change intended.
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-dns-scope.c | 7 | ||||
-rw-r--r-- | src/resolve/resolved-dns-trust-anchor.c | 13 |
2 files changed, 3 insertions, 17 deletions
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 4be6040e39..a9071ee73e 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -103,8 +103,6 @@ static void dns_scope_abort_transactions(DnsScope *s) { } DnsScope* dns_scope_free(DnsScope *s) { - DnsResourceRecord *rr; - if (!s) return NULL; @@ -119,10 +117,7 @@ DnsScope* dns_scope_free(DnsScope *s) { hashmap_free(s->transactions_by_key); - while ((rr = ordered_hashmap_steal_first(s->conflict_queue))) - dns_resource_record_unref(rr); - - ordered_hashmap_free(s->conflict_queue); + ordered_hashmap_free_with_destructor(s->conflict_queue, dns_resource_record_unref); sd_event_source_unref(s->conflict_event_source); sd_event_source_unref(s->announce_event_source); diff --git a/src/resolve/resolved-dns-trust-anchor.c b/src/resolve/resolved-dns-trust-anchor.c index f2bd9ef7e4..c6e47ed0e9 100644 --- a/src/resolve/resolved-dns-trust-anchor.c +++ b/src/resolve/resolved-dns-trust-anchor.c @@ -542,19 +542,10 @@ int dns_trust_anchor_load(DnsTrustAnchor *d) { } void dns_trust_anchor_flush(DnsTrustAnchor *d) { - DnsAnswer *a; - DnsResourceRecord *rr; - assert(d); - while ((a = hashmap_steal_first(d->positive_by_key))) - dns_answer_unref(a); - d->positive_by_key = hashmap_free(d->positive_by_key); - - while ((rr = set_steal_first(d->revoked_by_rr))) - dns_resource_record_unref(rr); - d->revoked_by_rr = set_free(d->revoked_by_rr); - + d->positive_by_key = hashmap_free_with_destructor(d->positive_by_key, dns_answer_unref); + d->revoked_by_rr = set_free_with_destructor(d->revoked_by_rr, dns_resource_record_unref); d->negative_by_name = set_free_free(d->negative_by_name); } |