diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-08-27 07:01:46 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-08-27 07:01:46 +0200 |
commit | 8301aa0bf145099e55443b8c10d00a62d20e0d29 (patch) | |
tree | dee970b9c80b599a83143e255d634e1293c89254 /src/resolve | |
parent | macro: introduce DEFINE_TRIVIAL_REF_UNREF_FUNC() macro and friends (diff) | |
download | systemd-8301aa0bf145099e55443b8c10d00a62d20e0d29.tar.xz systemd-8301aa0bf145099e55443b8c10d00a62d20e0d29.zip |
tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-dns-answer.c | 27 | ||||
-rw-r--r-- | src/resolve/resolved-dns-question.c | 31 | ||||
-rw-r--r-- | src/resolve/resolved-dns-rr.c | 24 | ||||
-rw-r--r-- | src/resolve/resolved-dns-search-domain.c | 23 | ||||
-rw-r--r-- | src/resolve/resolved-dns-server.c | 23 | ||||
-rw-r--r-- | src/resolve/resolved-dns-stream.c | 21 |
6 files changed, 29 insertions, 120 deletions
diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c index 66dc5d0299..6767dca302 100644 --- a/src/resolve/resolved-dns-answer.c +++ b/src/resolve/resolved-dns-answer.c @@ -19,15 +19,6 @@ DnsAnswer *dns_answer_new(size_t n) { return a; } -DnsAnswer *dns_answer_ref(DnsAnswer *a) { - if (!a) - return NULL; - - assert(a->n_ref > 0); - a->n_ref++; - return a; -} - static void dns_answer_flush(DnsAnswer *a) { DnsResourceRecord *rr; @@ -40,21 +31,15 @@ static void dns_answer_flush(DnsAnswer *a) { a->n_rrs = 0; } -DnsAnswer *dns_answer_unref(DnsAnswer *a) { - if (!a) - return NULL; - - assert(a->n_ref > 0); - - if (a->n_ref == 1) { - dns_answer_flush(a); - free(a); - } else - a->n_ref--; +static DnsAnswer *dns_answer_free(DnsAnswer *a) { + assert(a); - return NULL; + dns_answer_flush(a); + return mfree(a); } +DEFINE_TRIVIAL_REF_UNREF_FUNC(DnsAnswer, dns_answer, dns_answer_free); + static int dns_answer_add_raw(DnsAnswer *a, DnsResourceRecord *rr, int ifindex, DnsAnswerFlags flags) { assert(rr); diff --git a/src/resolve/resolved-dns-question.c b/src/resolve/resolved-dns-question.c index 68fb3b9eac..1ed9171564 100644 --- a/src/resolve/resolved-dns-question.c +++ b/src/resolve/resolved-dns-question.c @@ -20,33 +20,18 @@ DnsQuestion *dns_question_new(size_t n) { return q; } -DnsQuestion *dns_question_ref(DnsQuestion *q) { - if (!q) - return NULL; - - assert(q->n_ref > 0); - q->n_ref++; - return q; -} - -DnsQuestion *dns_question_unref(DnsQuestion *q) { - if (!q) - return NULL; - - assert(q->n_ref > 0); - - if (q->n_ref == 1) { - size_t i; +static DnsQuestion *dns_question_free(DnsQuestion *q) { + size_t i; - for (i = 0; i < q->n_keys; i++) - dns_resource_key_unref(q->keys[i]); - free(q); - } else - q->n_ref--; + assert(q); - return NULL; + for (i = 0; i < q->n_keys; i++) + dns_resource_key_unref(q->keys[i]); + return mfree(q); } +DEFINE_TRIVIAL_REF_UNREF_FUNC(DnsQuestion, dns_question, dns_question_free); + int dns_question_add(DnsQuestion *q, DnsResourceKey *key) { size_t i; int r; diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index e6d997ed97..67565d267e 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -399,26 +399,8 @@ DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, c return dns_resource_record_new(key); } -DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) { - if (!rr) - return NULL; - - assert(rr->n_ref > 0); - rr->n_ref++; - - return rr; -} - -DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) { - if (!rr) - return NULL; - - assert(rr->n_ref > 0); - - if (rr->n_ref > 1) { - rr->n_ref--; - return NULL; - } +static DnsResourceRecord* dns_resource_record_free(DnsResourceRecord *rr) { + assert(rr); if (rr->key) { switch(rr->key->type) { @@ -512,6 +494,8 @@ DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) { return mfree(rr); } +DEFINE_TRIVIAL_REF_UNREF_FUNC(DnsResourceRecord, dns_resource_record, dns_resource_record_free); + int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) { _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL; _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL; diff --git a/src/resolve/resolved-dns-search-domain.c b/src/resolve/resolved-dns-search-domain.c index c3817acf11..368ec4da19 100644 --- a/src/resolve/resolved-dns-search-domain.c +++ b/src/resolve/resolved-dns-search-domain.c @@ -65,30 +65,15 @@ int dns_search_domain_new( return 0; } -DnsSearchDomain* dns_search_domain_ref(DnsSearchDomain *d) { - if (!d) - return NULL; - - assert(d->n_ref > 0); - d->n_ref++; - - return d; -} - -DnsSearchDomain* dns_search_domain_unref(DnsSearchDomain *d) { - if (!d) - return NULL; - - assert(d->n_ref > 0); - d->n_ref--; - - if (d->n_ref > 0) - return NULL; +static DnsSearchDomain* dns_search_domain_free(DnsSearchDomain *d) { + assert(d); free(d->name); return mfree(d); } +DEFINE_TRIVIAL_REF_UNREF_FUNC(DnsSearchDomain, dns_search_domain, dns_search_domain_free); + void dns_search_domain_unlink(DnsSearchDomain *d) { assert(d); assert(d->manager); diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c index 24164362c4..be0ae7a731 100644 --- a/src/resolve/resolved-dns-server.c +++ b/src/resolve/resolved-dns-server.c @@ -98,25 +98,8 @@ int dns_server_new( return 0; } -DnsServer* dns_server_ref(DnsServer *s) { - if (!s) - return NULL; - - assert(s->n_ref > 0); - s->n_ref++; - - return s; -} - -DnsServer* dns_server_unref(DnsServer *s) { - if (!s) - return NULL; - - assert(s->n_ref > 0); - s->n_ref--; - - if (s->n_ref > 0) - return NULL; +static DnsServer* dns_server_free(DnsServer *s) { + assert(s); dns_stream_unref(s->stream); @@ -128,6 +111,8 @@ DnsServer* dns_server_unref(DnsServer *s) { return mfree(s); } +DEFINE_TRIVIAL_REF_UNREF_FUNC(DnsServer, dns_server, dns_server_free); + void dns_server_unlink(DnsServer *s) { assert(s); assert(s->manager); diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index c3ffc75930..9a5c7c34f3 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -424,18 +424,11 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use return 0; } -DnsStream *dns_stream_unref(DnsStream *s) { +static DnsStream *dns_stream_free(DnsStream *s) { DnsPacket *p; Iterator i; - if (!s) - return NULL; - - assert(s->n_ref > 0); - s->n_ref--; - - if (s->n_ref > 0) - return NULL; + assert(s); dns_stream_stop(s); @@ -464,15 +457,7 @@ DnsStream *dns_stream_unref(DnsStream *s) { return mfree(s); } -DnsStream *dns_stream_ref(DnsStream *s) { - if (!s) - return NULL; - - assert(s->n_ref > 0); - s->n_ref++; - - return s; -} +DEFINE_TRIVIAL_REF_UNREF_FUNC(DnsStream, dns_stream, dns_stream_free); int dns_stream_new(Manager *m, DnsStream **ret, DnsProtocol protocol, int fd, const union sockaddr_union *tfo_address) { _cleanup_(dns_stream_unrefp) DnsStream *s = NULL; |