4fbe94
From d95afbca80cf52f0bc84b2e1b4af6aadda007138 Mon Sep 17 00:00:00 2001
4fbe94
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
4fbe94
Date: Tue, 27 Aug 2019 19:02:53 +0200
4fbe94
Subject: [PATCH] resolved: do not run loop twice
4fbe94
4fbe94
This doesn't matter much, but let's just do the loop once and allocate
4fbe94
the populate the result set on the fly. If we find an error, it'll get
4fbe94
cleaned up automatically.
4fbe94
4fbe94
Related: #1746857
4fbe94
---
4fbe94
 src/resolve/resolved-link-bus.c | 13 ++++++-------
4fbe94
 1 file changed, 6 insertions(+), 7 deletions(-)
4fbe94
4fbe94
diff --git a/src/resolve/resolved-link-bus.c b/src/resolve/resolved-link-bus.c
4fbe94
index b1581740d8..46d2b11636 100644
4fbe94
--- a/src/resolve/resolved-link-bus.c
4fbe94
+++ b/src/resolve/resolved-link-bus.c
4fbe94
@@ -492,6 +492,10 @@ int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, v
4fbe94
         if (r < 0)
4fbe94
                 return r;
4fbe94
 
4fbe94
+        ns = set_new(&dns_name_hash_ops);
4fbe94
+        if (!ns)
4fbe94
+                return -ENOMEM;
4fbe94
+
4fbe94
         r = sd_bus_message_read_strv(message, &ntas);
4fbe94
         if (r < 0)
4fbe94
                 return r;
4fbe94
@@ -501,14 +505,9 @@ int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, v
4fbe94
                 if (r < 0)
4fbe94
                         return r;
4fbe94
                 if (r == 0)
4fbe94
-                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid negative trust anchor domain: %s", *i);
4fbe94
-        }
4fbe94
+                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
4fbe94
+                                                 "Invalid negative trust anchor domain: %s", *i);
4fbe94
 
4fbe94
-        ns = set_new(&dns_name_hash_ops);
4fbe94
-        if (!ns)
4fbe94
-                return -ENOMEM;
4fbe94
-
4fbe94
-        STRV_FOREACH(i, ntas) {
4fbe94
                 r = set_put_strdup(ns, *i);
4fbe94
                 if (r < 0)
4fbe94
                         return r;