return -ENOMEM;
*c = (DnsQueryCandidate) {
+ .n_ref = 1,
.query = q,
.scope = s,
};
}
}
-DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c) {
+static DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c) {
if (!c)
return NULL;
return mfree(c);
}
+DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(DnsQueryCandidate, dns_query_candidate, dns_query_candidate_free);
+
static int dns_query_candidate_next_search_domain(DnsQueryCandidate *c) {
DnsSearchDomain *next;
}
static int dns_query_candidate_go(DnsQueryCandidate *c) {
+ _cleanup_(dns_query_candidate_unrefp) DnsQueryCandidate *keep_c = NULL;
DnsTransaction *t;
int r;
unsigned n = 0;
- bool notify = false;
assert(c);
- c->query->block_ready++;
+ /* Let's keep a reference to the query while we're operating */
+ keep_c = dns_query_candidate_ref(c);
/* Start the transactions that are not started yet */
SET_FOREACH(t, c->transactions) {
continue;
r = dns_transaction_go(t);
- if (r < 0) {
- c->query->block_ready--;
+ if (r < 0)
return r;
- }
- if (r == 0)
- /* A transaction is complete. */
- notify = true;
n++;
}
- c->query->block_ready--;
-
/* If there was nothing to start, then let's proceed immediately */
- if (n == 0 || notify)
+ if (n == 0)
dns_query_candidate_notify(c);
return 0;
dns_query_candidate_stop(c);
}
-static void dns_query_free_candidates(DnsQuery *q) {
+static void dns_query_unref_candidates(DnsQuery *q) {
assert(q);
while (q->candidates)
- dns_query_candidate_free(q->candidates);
+ dns_query_candidate_unref(q->candidates);
}
static void dns_query_reset_answer(DnsQuery *q) {
LIST_REMOVE(auxiliary_queries, q->auxiliary_for->auxiliary_queries, q);
}
- dns_query_free_candidates(q);
+ dns_query_unref_candidates(q);
dns_question_unref(q->question_idna);
dns_question_unref(q->question_utf8);
}
static int dns_query_add_candidate(DnsQuery *q, DnsScope *s) {
- _cleanup_(dns_query_candidate_freep) DnsQueryCandidate *c = NULL;
+ _cleanup_(dns_query_candidate_unrefp) DnsQueryCandidate *c = NULL;
int r;
assert(q);
dns_question_unref(q->question_utf8);
q->question_utf8 = TAKE_PTR(nq_utf8);
- dns_query_free_candidates(q);
+ dns_query_unref_candidates(q);
dns_query_reset_answer(q);
q->state = DNS_TRANSACTION_NULL;
#include "resolved-dns-transaction.h"
struct DnsQueryCandidate {
+ unsigned n_ref;
+ int error_code;
+
DnsQuery *query;
DnsScope *scope;
DnsSearchDomain *search_domain;
- int error_code;
Set *transactions;
LIST_FIELDS(DnsQueryCandidate, candidates_by_query);
DNS_QUERY_RESTARTED,
};
-DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c);
-DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQueryCandidate*, dns_query_candidate_free);
+DnsQueryCandidate* dns_query_candidate_ref(DnsQueryCandidate*);
+DnsQueryCandidate* dns_query_candidate_unref(DnsQueryCandidate*);
+DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQueryCandidate*, dns_query_candidate_unref);
void dns_query_candidate_notify(DnsQueryCandidate *c);