]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: make both search_domains and route_domains allocated on DBus call
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 26 Nov 2021 08:03:11 +0000 (17:03 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 26 Nov 2021 11:20:06 +0000 (20:20 +0900)
src/network/networkd-link-bus.c

index 47e0d40d5768674734d9eddc1547711ebe891bda..765733b38c4f9ab7843c9c2f560084b612737e48 100644 (file)
@@ -195,9 +195,16 @@ int bus_link_method_set_domains(sd_bus_message *message, void *userdata, sd_bus_
         if (r < 0)
                 return r;
 
+        search_domains = ordered_set_new(&string_hash_ops_free);
+        if (!search_domains)
+                return -ENOMEM;
+
+        route_domains = ordered_set_new(&string_hash_ops_free);
+        if (!route_domains)
+                return -ENOMEM;
+
         for (;;) {
                 _cleanup_free_ char *str = NULL;
-                OrderedSet **domains;
                 const char *name;
                 int route_only;
 
@@ -219,12 +226,7 @@ int bus_link_method_set_domains(sd_bus_message *message, void *userdata, sd_bus_
                 if (r < 0)
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid search domain %s", name);
 
-                domains = route_only ? &route_domains : &search_domains;
-                r = ordered_set_ensure_allocated(domains, &string_hash_ops_free);
-                if (r < 0)
-                        return r;
-
-                r = ordered_set_consume(*domains, TAKE_PTR(str));
+                r = ordered_set_consume(route_only ? route_domains : search_domains, TAKE_PTR(str));
                 if (r == -EEXIST)
                         continue;
                 if (r < 0)