1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

tree-wide: use _cleanup_ attribute and strv_consume() + TAKE_PTR()

This commit is contained in:
Yu Watanabe 2019-06-24 14:57:58 +09:00
parent 623550aff7
commit 6abdec98f3
4 changed files with 17 additions and 24 deletions

View File

@ -720,8 +720,7 @@ int get_kernel_consoles(char ***ret) {
p = line; p = line;
for (;;) { for (;;) {
_cleanup_free_ char *tty = NULL; _cleanup_free_ char *tty = NULL, *path = NULL;
char *path;
r = extract_first_word(&p, &tty, NULL, 0); r = extract_first_word(&p, &tty, NULL, 0);
if (r < 0) if (r < 0)
@ -736,17 +735,16 @@ int get_kernel_consoles(char ***ret) {
return r; return r;
} }
path = strappend("/dev/", tty); path = path_join("/dev", tty);
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
if (access(path, F_OK) < 0) { if (access(path, F_OK) < 0) {
log_debug_errno(errno, "Console device %s is not accessible, skipping: %m", path); log_debug_errno(errno, "Console device %s is not accessible, skipping: %m", path);
free(path);
continue; continue;
} }
r = strv_consume(&l, path); r = strv_consume(&l, TAKE_PTR(path));
if (r < 0) if (r < 0)
return r; return r;
} }

View File

@ -2108,22 +2108,19 @@ int bus_exec_context_set_transient_property(
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
_cleanup_free_ char *q = NULL; _cleanup_free_ char *q = NULL, *buf = NULL;
char *buf;
buf = strjoin(b ? "-" : "", path); buf = strjoin(b ? "-" : "", path);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
q = specifier_escape(buf); q = specifier_escape(buf);
if (!q) { if (!q)
free(buf);
return -ENOMEM; return -ENOMEM;
}
fprintf(f, "EnvironmentFile=%s\n", q); fprintf(f, "EnvironmentFile=%s\n", q);
r = strv_consume(&l, buf); r = strv_consume(&l, TAKE_PTR(buf));
if (r < 0) if (r < 0)
return r; return r;
} }

View File

@ -61,8 +61,8 @@ int pull_find_old_etags(
} }
FOREACH_DIRENT_ALL(de, d, return -errno) { FOREACH_DIRENT_ALL(de, d, return -errno) {
_cleanup_free_ char *u = NULL;
const char *a, *b; const char *a, *b;
char *u;
if (de->d_type != DT_UNKNOWN && if (de->d_type != DT_UNKNOWN &&
de->d_type != dt) de->d_type != dt)
@ -97,12 +97,10 @@ int pull_find_old_etags(
if (r < 0) if (r < 0)
return r; return r;
if (!http_etag_is_valid(u)) { if (!http_etag_is_valid(u))
free(u);
continue; continue;
}
r = strv_consume(&l, u); r = strv_consume(&l, TAKE_PTR(u));
if (r < 0) if (r < 0)
return r; return r;
} }

View File

@ -1229,7 +1229,7 @@ static int map_link_dns_servers(sd_bus *bus, const char *member, sd_bus_message
return r; return r;
for (;;) { for (;;) {
char *pretty = NULL; _cleanup_free_ char *pretty = NULL;
r = read_dns_server_one(m, false, &pretty); r = read_dns_server_one(m, false, &pretty);
if (r < 0) if (r < 0)
@ -1240,7 +1240,7 @@ static int map_link_dns_servers(sd_bus *bus, const char *member, sd_bus_message
if (isempty(pretty)) if (isempty(pretty))
continue; continue;
r = strv_consume(l, pretty); r = strv_consume(l, TAKE_PTR(pretty));
if (r < 0) if (r < 0)
return r; return r;
} }
@ -1306,7 +1306,7 @@ static int map_link_domains(sd_bus *bus, const char *member, sd_bus_message *m,
return r; return r;
for (;;) { for (;;) {
char *pretty = NULL; _cleanup_free_ char *pretty = NULL;
r = read_domain_one(m, false, &pretty); r = read_domain_one(m, false, &pretty);
if (r < 0) if (r < 0)
@ -1317,7 +1317,7 @@ static int map_link_domains(sd_bus *bus, const char *member, sd_bus_message *m,
if (isempty(pretty)) if (isempty(pretty))
continue; continue;
r = strv_consume(l, pretty); r = strv_consume(l, TAKE_PTR(pretty));
if (r < 0) if (r < 0)
return r; return r;
} }
@ -1536,7 +1536,7 @@ static int map_global_dns_servers(sd_bus *bus, const char *member, sd_bus_messag
return r; return r;
for (;;) { for (;;) {
char *pretty = NULL; _cleanup_free_ char *pretty = NULL;
r = read_dns_server_one(m, true, &pretty); r = read_dns_server_one(m, true, &pretty);
if (r < 0) if (r < 0)
@ -1547,7 +1547,7 @@ static int map_global_dns_servers(sd_bus *bus, const char *member, sd_bus_messag
if (isempty(pretty)) if (isempty(pretty))
continue; continue;
r = strv_consume(l, pretty); r = strv_consume(l, TAKE_PTR(pretty));
if (r < 0) if (r < 0)
return r; return r;
} }
@ -1580,7 +1580,7 @@ static int map_global_domains(sd_bus *bus, const char *member, sd_bus_message *m
return r; return r;
for (;;) { for (;;) {
char *pretty = NULL; _cleanup_free_ char *pretty = NULL;
r = read_domain_one(m, true, &pretty); r = read_domain_one(m, true, &pretty);
if (r < 0) if (r < 0)
@ -1591,7 +1591,7 @@ static int map_global_domains(sd_bus *bus, const char *member, sd_bus_message *m
if (isempty(pretty)) if (isempty(pretty))
continue; continue;
r = strv_consume(l, pretty); r = strv_consume(l, TAKE_PTR(pretty));
if (r < 0) if (r < 0)
return r; return r;
} }