From: Lennart Poettering Date: Tue, 19 Mar 2019 12:01:12 +0000 (+0100) Subject: core: check for redundant operation before doing allocation X-Git-Tag: v243-rc1~571^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5210387ea66655dfcc3264b3c44f95b373c0f719;p=thirdparty%2Fsystemd.git core: check for redundant operation before doing allocation --- diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 5bac54f36d0..01d72a39081 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -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;