From 623550aff7f290a180473cd1a713f1c5ba882d8a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 24 Jun 2019 14:57:50 +0900 Subject: [PATCH] sd-path: use _cleanup_strv_free_ attribute --- src/libsystemd/sd-path/sd-path.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 12ff30ef86..2dfde4ca71 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -388,9 +388,9 @@ static int search_from_environment( bool env_search_sufficient, const char *first, ...) { + _cleanup_strv_free_ char **l = NULL; const char *e; char *h = NULL; - char **l = NULL; int r; assert(list); @@ -403,7 +403,7 @@ static int search_from_environment( return -ENOMEM; if (env_search_sufficient) { - *list = l; + *list = TAKE_PTR(l); return 0; } } @@ -424,10 +424,8 @@ static int search_from_environment( e = secure_getenv(env_home); if (e && path_is_absolute(e)) { h = strdup(e); - if (!h) { - strv_free(l); + if (!h) return -ENOMEM; - } } } @@ -435,23 +433,18 @@ static int search_from_environment( e = secure_getenv("HOME"); if (e && path_is_absolute(e)) { h = path_join(e, home_suffix); - - if (!h) { - strv_free(l); + if (!h) return -ENOMEM; - } } } if (h) { r = strv_consume_prepend(&l, h); - if (r < 0) { - strv_free(l); + if (r < 0) return -ENOMEM; - } } - *list = l; + *list = TAKE_PTR(l); return 0; } -- 2.25.1