diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-03-04 09:20:51 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-03-04 10:04:50 -0500 |
commit | 6e18964d3a365567954fe10ddcfad74babdc427c (patch) | |
tree | a1e62c233e0cac0224623049e6fb98b8e450d0ac /src/shared | |
parent | e062dec5ae1a443d47885537af85d328c83c67db (diff) |
Introduce strv_consume which takes ownership
This mirrors set_consume and makes the common use a bit nicer.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/acl-util.c | 3 | ||||
-rw-r--r-- | src/shared/conf-parser.c | 4 | ||||
-rw-r--r-- | src/shared/fileio.c | 6 | ||||
-rw-r--r-- | src/shared/strv.c | 17 | ||||
-rw-r--r-- | src/shared/strv.h | 1 |
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); |