summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-04 09:20:51 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-04 10:04:50 -0500
commit6e18964d3a365567954fe10ddcfad74babdc427c (patch)
treea1e62c233e0cac0224623049e6fb98b8e450d0ac /src
parente062dec5ae1a443d47885537af85d328c83c67db (diff)
Introduce strv_consume which takes ownership
This mirrors set_consume and makes the common use a bit nicer.
Diffstat (limited to 'src')
-rw-r--r--src/bus-driverd/bus-driverd.c8
-rw-r--r--src/core/dbus-execute.c8
-rw-r--r--src/core/locale-setup.c3
-rw-r--r--src/core/unit.c6
-rw-r--r--src/libsystemd/sd-bus/bus-control.c8
-rw-r--r--src/login/logind-seat-dbus.c6
-rw-r--r--src/login/logind-session-dbus.c6
-rw-r--r--src/login/logind-user-dbus.c6
-rw-r--r--src/machine/machine-dbus.c6
-rw-r--r--src/shared/acl-util.c3
-rw-r--r--src/shared/conf-parser.c4
-rw-r--r--src/shared/fileio.c6
-rw-r--r--src/shared/strv.c17
-rw-r--r--src/shared/strv.h1
-rw-r--r--src/systemctl/systemctl.c16
15 files changed, 42 insertions, 62 deletions
diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index 54059604b1..3284d62534 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -562,11 +562,9 @@ static int driver_list_queued_owners(sd_bus *bus, sd_bus_message *m, void *userd
if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
return -ENOMEM;
- r = strv_push(&owners, n);
- if (r < 0) {
- free(n);
- return -ENOMEM;
- }
+ r = strv_consume(&owners, n);
+ if (r < 0)
+ return r;
}
r = ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd.offset);
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index 6d0bdce9dc..3a05303f08 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -385,11 +385,9 @@ static int property_get_syscall_filter(
if (!name)
continue;
- r = strv_push(&l, name);
- if (r < 0) {
- free(name);
- return -ENOMEM;
- }
+ r = strv_consume(&l, name);
+ if (r < 0)
+ return r;
}
#endif
diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c
index 276deb9dc1..7a4103504f 100644
--- a/src/core/locale-setup.c
+++ b/src/core/locale-setup.c
@@ -133,8 +133,7 @@ int locale_setup(char ***environment) {
goto finish;
}
- if (strv_push(&add, s) < 0) {
- free(s);
+ if (strv_consume(&add, s) < 0) {
r = -ENOMEM;
goto finish;
}
diff --git a/src/core/unit.c b/src/core/unit.c
index 1c0b0c72ac..d0e915909a 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -3181,11 +3181,9 @@ int unit_require_mounts_for(Unit *u, const char *path) {
return 0;
}
- r = strv_push(&u->requires_mounts_for, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&u->requires_mounts_for, p);
+ if (r < 0)
return r;
- }
PATH_FOREACH_PREFIX_MORE(prefix, p) {
Set *x;
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 22b95d589d..db0c11b0fe 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -237,11 +237,9 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
return -ENOMEM;
- r = strv_push(x, n);
- if (r < 0) {
- free(n);
- return -ENOMEM;
- }
+ r = strv_consume(x, n);
+ if (r < 0)
+ return r;
previous_id = name->owner_id;
}
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 26cddfea70..315e6baf6b 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -399,11 +399,9 @@ int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index f9305ddbee..fc728bb9d6 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -558,11 +558,9 @@ int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index 18eea89701..b5d27e74de 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -315,11 +315,9 @@ int user_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index df96ccf9d4..c9e3bb7c75 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -225,11 +225,9 @@ int machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c
index fb04e49dc4..c93f58a739 100644
--- a/src/shared/acl-util.c
+++ b/src/shared/acl-util.c
@@ -136,9 +136,8 @@ int search_acl_groups(char*** dst, const char* path, bool* belong) {
return log_oom();
}
- r = strv_push(dst, name);
+ r = strv_consume(dst, name);
if (r < 0) {
- free(name);
acl_free(acl);
return log_oom();
}
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 86435d3bde..0a87a71513 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -681,7 +681,7 @@ int config_parse_strv(const char *unit,
}
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- _cleanup_free_ char *n;
+ char *n;
n = cunescape_length(w, l);
if (!n)
@@ -693,7 +693,7 @@ int config_parse_strv(const char *unit,
continue;
}
- r = strv_extend(sv, n);
+ r = strv_consume(sv, n);
if (r < 0)
return log_oom();
}
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index 0d3f2e90c7..d5915673d6 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -614,11 +614,9 @@ static int load_env_file_push(const char *filename, unsigned line,
if (!p)
return -ENOMEM;
- r = strv_push(m, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(m, p);
+ if (r < 0)
return r;
- }
free(value);
return 0;
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 13deba7be7..67706dc381 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -378,9 +378,18 @@ int strv_push(char ***l, char *value) {
return 0;
}
+int strv_consume(char ***l, char *value) {
+ int r;
+
+ r = strv_push(l, value);
+ if (r < 0)
+ free(value);
+
+ return r;
+}
+
int strv_extend(char ***l, const char *value) {
char *v;
- int r;
if (!value)
return 0;
@@ -389,11 +398,7 @@ int strv_extend(char ***l, const char *value) {
if (!v)
return -ENOMEM;
- r = strv_push(l, v);
- if (r < 0)
- free(v);
-
- return r;
+ return strv_consume(l, v);
}
char **strv_uniq(char **l) {
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 715bc5419c..13a4bb6cf1 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -40,6 +40,7 @@ int strv_extend_strv(char ***a, char **b);
int strv_extend_strv_concat(char ***a, char **b, const char *suffix);
int strv_extend(char ***l, const char *value);
int strv_push(char ***l, char *value);
+int strv_consume(char ***l, char *value);
char **strv_remove(char **l, const char *s);
char **strv_uniq(char **l);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 869271628f..952d2f8358 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2167,13 +2167,11 @@ static int expand_names(sd_bus *bus, char **names, const char* suffix, char ***r
return log_oom();
if (string_is_glob(t))
- r = strv_push(&globs, t);
+ r = strv_consume(&globs, t);
else
- r = strv_push(&mangled, t);
- if (r < 0) {
- free(t);
+ r = strv_consume(&mangled, t);
+ if (r < 0)
return log_oom();
- }
}
/* Query the manager only if any of the names are a glob, since
@@ -5346,10 +5344,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
if (!prop)
return log_oom();
- if (strv_push(&arg_properties, prop) < 0) {
- free(prop);
+ if (strv_consume(&arg_properties, prop) < 0)
return log_oom();
- }
}
}
@@ -5518,10 +5514,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
if (!s)
return log_oom();
- if (strv_push(&arg_states, s) < 0) {
- free(s);
+ if (strv_consume(&arg_states, s) < 0)
return log_oom();
- }
}
break;
}