]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: check for redundant operation before doing allocation
authorLennart Poettering <lennart@poettering.net>
Tue, 19 Mar 2019 12:01:12 +0000 (13:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 9 Apr 2019 09:17:57 +0000 (11:17 +0200)
src/core/cgroup.c

index 5bac54f36d055aba8e841b8e093248aef0c78bc7..01d72a390817389ad6feb7cb22eca65b4c9d22c7 100644 (file)
@@ -1568,15 +1568,14 @@ int unit_set_cgroup_path(Unit *u, const char *path) {
 
         assert(u);
 
+        if (streq_ptr(u->cgroup_path, path))
+                return 0;
+
         if (path) {
                 p = strdup(path);
                 if (!p)
                         return -ENOMEM;
-        } else
-                p = NULL;
-
-        if (streq_ptr(u->cgroup_path, p))
-                return 0;
+        }
 
         if (p) {
                 r = hashmap_put(u->manager->cgroup_unit, p, u);
@@ -1585,7 +1584,6 @@ int unit_set_cgroup_path(Unit *u, const char *path) {
         }
 
         unit_release_cgroup(u);
-
         u->cgroup_path = TAKE_PTR(p);
 
         return 1;