core: use _cleanup_free_ attribute and free_and_replace() macro in method_switch_root()

This commit is contained in:
Yu Watanabe
2019-03-15 18:59:31 +09:00
parent 3ac35cbc2b
commit 87a19bfedc
+4 -9
View 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;