]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-path: use _cleanup_strv_free_ attribute
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 24 Jun 2019 05:57:50 +0000 (14:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 24 Jun 2019 05:57:50 +0000 (14:57 +0900)
src/libsystemd/sd-path/sd-path.c

index 12ff30ef86f63b5a07ade24f6b5874ee2661637b..2dfde4ca7172d1c07e26afe49a600b47dd2057a6 100644 (file)
@@ -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;
 }