]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: strjoina() in a loop is never OK
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Oct 2018 18:32:20 +0000 (20:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Oct 2018 08:40:01 +0000 (10:40 +0200)
Let's use plain strjoin() instead.

src/core/manager.c

index 6a18e97065653108ac29395a4d24245968bf0a4f..c4fb60984a67f30dc7ab295dacc7d633c221d350 100644 (file)
@@ -3118,6 +3118,8 @@ int manager_serialize(
                 fprintf(f, "log-target-override=%s\n", log_target_to_string(log_get_target()));
 
         for (q = 0; q < _MANAGER_TIMESTAMP_MAX; q++) {
+                _cleanup_free_ char *joined = NULL;
+
                 /* The following timestamps only apply to the host system, hence only serialize them there */
                 if (in_initrd() &&
                     IN_SET(q, MANAGER_TIMESTAMP_USERSPACE, MANAGER_TIMESTAMP_FINISH,
@@ -3126,9 +3128,11 @@ int manager_serialize(
                            MANAGER_TIMESTAMP_UNITS_LOAD_START, MANAGER_TIMESTAMP_UNITS_LOAD_FINISH))
                         continue;
 
-                t = manager_timestamp_to_string(q);
-                const char *field = strjoina(t, "-timestamp");
-                dual_timestamp_serialize(f, field, m->timestamps + q);
+                joined = strjoin(manager_timestamp_to_string(q), "-timestamp");
+                if (!joined)
+                        return log_oom();
+
+                dual_timestamp_serialize(f, joined, m->timestamps + q);
         }
 
         if (!switching_root)