summaryrefslogtreecommitdiff
path: root/src/basic/nulstr-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-11-11 22:01:03 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-11-13 17:39:08 +0900
commiteecac5053b1aff31f43df7aa053a4561b5a8740c (patch)
treede896b0a872b32b2cbe57b4e6e7d16430e0d7d18 /src/basic/nulstr-util.c
parent8ba17a319bdbcacf16b2dfe0a759d0e43971e71d (diff)
downloadsystemd-eecac5053b1aff31f43df7aa053a4561b5a8740c.tar.gz
nulstr-util: use _cleanup_strv_free_() where appropriate
Diffstat (limited to 'src/basic/nulstr-util.c')
-rw-r--r--src/basic/nulstr-util.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/basic/nulstr-util.c b/src/basic/nulstr-util.c
index 1b6af6ffd7..e8e5629e95 100644
--- a/src/basic/nulstr-util.c
+++ b/src/basic/nulstr-util.c
@@ -13,8 +13,8 @@ char** strv_parse_nulstr(const char *s, size_t l) {
* Note that contrary to a normal nulstr which cannot contain empty strings, because the input data
* is terminated by any two consequent NUL bytes, this parser accepts empty strings in s. */
+ _cleanup_strv_free_ char **v = NULL;
size_t c = 0, i = 0;
- char **v;
assert(s || l <= 0);
@@ -38,10 +38,8 @@ char** strv_parse_nulstr(const char *s, size_t l) {
e = memchr(p, 0, s + l - p);
v[i] = strndup(p, e ? e - p : s + l - p);
- if (!v[i]) {
- strv_free(v);
+ if (!v[i])
return NULL;
- }
i++;
@@ -53,22 +51,20 @@ char** strv_parse_nulstr(const char *s, size_t l) {
assert(i == c);
- return v;
+ return TAKE_PTR(v);
}
char** strv_split_nulstr(const char *s) {
- char **r = NULL;
+ _cleanup_strv_free_ char **r = NULL;
NULSTR_FOREACH(i, s)
- if (strv_extend(&r, i) < 0) {
- strv_free(r);
+ if (strv_extend(&r, i) < 0)
return NULL;
- }
if (!r)
return strv_new(NULL);
- return r;
+ return TAKE_PTR(r);
}
int strv_make_nulstr(char * const *l, char **ret, size_t *ret_size) {