machinectl: use strdup_to() and move cleanup out of the loop

It doesn't matter much, but it seems nicer to call va_end() just
once.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-20 15:18:21 +01:00
parent 4ab305fa3b
commit 237bbec117
+6 -8
View File
@@ -159,24 +159,22 @@ static int call_get_os_release(sd_bus *bus, const char *method, const char *name
if (r < 0)
return bus_log_parse_error(r);
r = 0;
va_start(ap, query);
for (count = 0; count < awaited_args; count++) {
char *val, **out;
char **out;
out = va_arg(ap, char **);
assert(out);
if (query_res[count]) {
val = strdup(query_res[count]);
if (!val) {
va_end(ap);
return -ENOMEM;
}
*out = val;
r = strdup_to(out, query_res[count]);
if (r < 0)
break;
}
}
va_end(ap);
return 0;
return r;
}
static int call_get_addresses(