]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: introduce dns_transaction_gcp()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Jun 2020 12:25:18 +0000 (14:25 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 22 Jun 2020 14:32:37 +0000 (16:32 +0200)
src/resolve/resolved-dns-query.c
src/resolve/resolved-dns-transaction.c
src/resolve/resolved-dns-transaction.h
src/resolve/resolved-dns-zone.c

index d6eca6dfdd75d1bf93901ac793e281bedff9a380..89e5d3bf67de64c5290df1c20e5f0d48ef7003b2 100644 (file)
@@ -94,7 +94,7 @@ static int dns_query_candidate_next_search_domain(DnsQueryCandidate *c) {
 }
 
 static int dns_query_candidate_add_transaction(DnsQueryCandidate *c, DnsResourceKey *key) {
-        DnsTransaction *t;
+        _cleanup_(dns_transaction_gcp) DnsTransaction *t = NULL;
         int r;
 
         assert(c);
@@ -105,39 +105,34 @@ static int dns_query_candidate_add_transaction(DnsQueryCandidate *c, DnsResource
                 r = dns_transaction_new(&t, c->scope, key);
                 if (r < 0)
                         return r;
-        } else {
-                if (set_contains(c->transactions, t))
-                        return 0;
-        }
+        } else if (set_contains(c->transactions, t))
+                return 0;
 
         r = set_ensure_allocated(&c->transactions, NULL);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_ensure_allocated(&t->notify_query_candidates, NULL);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_ensure_allocated(&t->notify_query_candidates_done, NULL);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_put(t->notify_query_candidates, c);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_put(c->transactions, t);
         if (r < 0) {
                 (void) set_remove(t->notify_query_candidates, c);
-                goto gc;
+                return r;
         }
 
         t->clamp_ttl = c->query->clamp_ttl;
+        TAKE_PTR(t);
         return 1;
-
-gc:
-        dns_transaction_gc(t);
-        return r;
 }
 
 static int dns_query_candidate_go(DnsQueryCandidate *c) {
index 5898308d5fa46f6060d0c83c4743028ce49dee86..46854a5ad4a5ebac413c98bb7a9421426c3837f6 100644 (file)
@@ -1800,7 +1800,7 @@ static int dns_transaction_find_cyclic(DnsTransaction *t, DnsTransaction *aux) {
 }
 
 static int dns_transaction_add_dnssec_transaction(DnsTransaction *t, DnsResourceKey *key, DnsTransaction **ret) {
-        DnsTransaction *aux;
+        _cleanup_(dns_transaction_gcp) DnsTransaction *aux = NULL;
         int r;
 
         assert(t);
@@ -1835,32 +1835,28 @@ static int dns_transaction_add_dnssec_transaction(DnsTransaction *t, DnsResource
 
         r = set_ensure_allocated(&t->dnssec_transactions, NULL);
         if (r < 0)
-                goto gc;
+                return r;;
 
         r = set_ensure_allocated(&aux->notify_transactions, NULL);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_ensure_allocated(&aux->notify_transactions_done, NULL);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_put(t->dnssec_transactions, aux);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_put(aux->notify_transactions, t);
         if (r < 0) {
                 (void) set_remove(t->dnssec_transactions, aux);
-                goto gc;
+                return r;
         }
 
-        *ret = aux;
+        *ret = TAKE_PTR(aux);
         return 1;
-
-gc:
-        dns_transaction_gc(aux);
-        return r;
 }
 
 static int dns_transaction_request_dnssec_rr(DnsTransaction *t, DnsResourceKey *key) {
index b1d4348409fc41aab1fa41e4b756acbf195078fb..167541806a28eaa5f0deac78cc7664bf271ba1e8 100644 (file)
@@ -138,6 +138,8 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
 DnsTransaction* dns_transaction_free(DnsTransaction *t);
 
 bool dns_transaction_gc(DnsTransaction *t);
+DEFINE_TRIVIAL_CLEANUP_FUNC(DnsTransaction*, dns_transaction_gc);
+
 int dns_transaction_go(DnsTransaction *t);
 
 void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
index 0ef4c892f7066f9d9d64771935074866dc20299a..827ad529e1fe1128cf41800cef9cdd08aaa8fc84 100644 (file)
@@ -162,7 +162,7 @@ static int dns_zone_link_item(DnsZone *z, DnsZoneItem *i) {
 }
 
 static int dns_zone_item_probe_start(DnsZoneItem *i)  {
-        DnsTransaction *t;
+        _cleanup_(dns_transaction_gcp) DnsTransaction *t = NULL;
         int r;
 
         assert(i);
@@ -185,23 +185,22 @@ static int dns_zone_item_probe_start(DnsZoneItem *i)  {
 
         r = set_ensure_allocated(&t->notify_zone_items, NULL);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_ensure_allocated(&t->notify_zone_items_done, NULL);
         if (r < 0)
-                goto gc;
+                return r;
 
         r = set_put(t->notify_zone_items, i);
         if (r < 0)
-                goto gc;
+                return r;
 
-        i->probe_transaction = t;
         t->probing = true;
+        i->probe_transaction = TAKE_PTR(t);
 
-        if (t->state == DNS_TRANSACTION_NULL) {
-
+        if (i->probe_transaction->state == DNS_TRANSACTION_NULL) {
                 i->block_ready++;
-                r = dns_transaction_go(t);
+                r = dns_transaction_go(i->probe_transaction);
                 i->block_ready--;
 
                 if (r < 0) {
@@ -212,10 +211,6 @@ static int dns_zone_item_probe_start(DnsZoneItem *i)  {
 
         dns_zone_item_notify(i);
         return 0;
-
-gc:
-        dns_transaction_gc(t);
-        return r;
 }
 
 int dns_zone_put(DnsZone *z, DnsScope *s, DnsResourceRecord *rr, bool probe) {