]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/serialize.c
strv: make iterator in STRV_FOREACH() declaread in the loop
[thirdparty/systemd.git] / src / shared / serialize.c
index 00b70a777ee3a10aca42a701081758a99d32e434..cd48286355715af6a845ceca08a56ac63b2001d4 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <fcntl.h>
 
@@ -117,7 +117,6 @@ int serialize_dual_timestamp(FILE *f, const char *name, const dual_timestamp *t)
 
 int serialize_strv(FILE *f, const char *key, char **l) {
         int ret = 0, r;
-        char **i;
 
         /* Returns the first error, or positive if anything was serialized, 0 otherwise. */
 
@@ -176,6 +175,7 @@ int deserialize_dual_timestamp(const char *value, dual_timestamp *t) {
 
 int deserialize_environment(const char *value, char ***list) {
         _cleanup_free_ char *unescaped = NULL;
+        ssize_t l;
         int r;
 
         assert(value);
@@ -183,15 +183,14 @@ int deserialize_environment(const char *value, char ***list) {
 
         /* Changes the *environment strv inline. */
 
-        r = cunescape(value, 0, &unescaped);
-        if (r < 0)
-                return log_error_errno(r, "Failed to unescape: %m");
+        l = cunescape(value, 0, &unescaped);
+        if (l < 0)
+                return log_error_errno(l, "Failed to unescape: %m");
 
-        r = strv_env_replace(list, unescaped);
+        r = strv_env_replace_consume(list, TAKE_PTR(unescaped));
         if (r < 0)
                 return log_error_errno(r, "Failed to append environment variable: %m");
 
-        unescaped = NULL; /* now part of 'list' */
         return 0;
 }