]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: use _cleanup_free_ attribute and free_and_replace() macro in method_switch_root()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 15 Mar 2019 09:59:31 +0000 (18:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 15 Mar 2019 09:59:31 +0000 (18:59 +0900)
src/core/dbus-manager.c

index 88e4c6bb952099f9805936aec0e5dda4010cc364..c52f94c8f229dd77d3b3d807dbf2a3d708e8e543 100644 (file)
@@ -1490,7 +1490,7 @@ static int method_kexec(sd_bus_message *message, void *userdata, sd_bus_error *e
 }
 
 static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_error *error) {
-        char *ri = NULL, *rt = NULL;
+        _cleanup_free_ char *ri = NULL, *rt = NULL;
         const char *root, *init;
         Manager *m = userdata;
         struct statvfs svfs;
@@ -1562,17 +1562,12 @@ static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_er
 
         if (!isempty(init)) {
                 ri = strdup(init);
-                if (!ri) {
-                        free(rt);
+                if (!ri)
                         return -ENOMEM;
-                }
         }
 
-        free(m->switch_root);
-        m->switch_root = rt;
-
-        free(m->switch_root_init);
-        m->switch_root_init = ri;
+        free_and_replace(m->switch_root, rt);
+        free_and_replace(m->switch_root_init, ri);
 
         m->objective = MANAGER_SWITCH_ROOT;