DEFINE_HASH_OPS(dns_resource_record_hash_ops, DnsResourceRecord, dns_resource_record_hash_func, dns_resource_record_compare_func);
+DEFINE_HASH_OPS_FULL(
+ dns_resource_record_hash_ops_by_key,
+ DnsResourceKey,
+ dns_resource_key_hash_func,
+ dns_resource_key_compare_func,
+ dns_resource_key_unref,
+ DnsResourceRecord,
+ dns_resource_record_unref);
+
DnsResourceRecord *dns_resource_record_copy(DnsResourceRecord *rr) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *copy = NULL;
DnsResourceRecord *t;
hashmap_free(s->transactions_by_key);
- ordered_hashmap_free_with_destructor(s->conflict_queue, dns_resource_record_unref);
+ ordered_hashmap_free(s->conflict_queue);
sd_event_source_disable_unref(s->conflict_event_source);
sd_event_source_disable_unref(s->announce_event_source);
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
- key = ordered_hashmap_first_key(scope->conflict_queue);
- if (!key)
+ rr = ordered_hashmap_steal_first_key_and_value(scope->conflict_queue, (void**) &key);
+ if (!rr)
break;
- rr = ordered_hashmap_remove(scope->conflict_queue, key);
- assert(rr);
-
r = dns_scope_make_conflict_packet(scope, rr, &p);
if (r < 0) {
log_error_errno(r, "Failed to make conflict packet: %m");
assert(scope);
assert(rr);
- /* We don't send these queries immediately. Instead, we queue
- * them, and send them after some jitter delay. */
- r = ordered_hashmap_ensure_allocated(&scope->conflict_queue, &dns_resource_key_hash_ops);
- if (r < 0) {
- log_oom();
- return r;
- }
-
- /* We only place one RR per key in the conflict
- * messages, not all of them. That should be enough to
- * indicate where there might be a conflict */
- r = ordered_hashmap_put(scope->conflict_queue, rr->key, rr);
+ /* We don't send these queries immediately. Instead, we queue them, and send them after some jitter
+ * delay. We only place one RR per key in the conflict messages, not all of them. That should be
+ * enough to indicate where there might be a conflict */
+ r = ordered_hashmap_ensure_put(&scope->conflict_queue, &dns_resource_record_hash_ops_by_key, rr->key, rr);
if (IN_SET(r, 0, -EEXIST))
return 0;
if (r < 0)