summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-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
5 files changed, 17 insertions, 14 deletions
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);