]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: modernize device_set_sysfs() a bit
authorLennart Poettering <lennart@poettering.net>
Mon, 4 Jun 2018 16:03:02 +0000 (18:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Jun 2018 11:36:19 +0000 (13:36 +0200)
src/core/device.c

index b3f8eb4e02371c8efb1d289f77430bf133966567..725aa9d3bf42d238d23c2369659fd21134e34cbf 100644 (file)
@@ -55,8 +55,8 @@ static void device_unset_sysfs(Device *d) {
 }
 
 static int device_set_sysfs(Device *d, const char *sysfs) {
+        _cleanup_free_ char *copy = NULL;
         Device *first;
-        char *copy;
         int r;
 
         assert(d);
@@ -80,12 +80,10 @@ static int device_set_sysfs(Device *d, const char *sysfs) {
         r = hashmap_replace(UNIT(d)->manager->devices_by_sysfs, copy, first);
         if (r < 0) {
                 LIST_REMOVE(same_sysfs, first, d);
-                free(copy);
                 return r;
         }
 
-        d->sysfs = copy;
-
+        d->sysfs = TAKE_PTR(copy);
         return 0;
 }