summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-03-15 18:59:31 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-03-15 18:59:31 +0900
commit87a19bfedcd132822974fa096f03e0e0b6de1099 (patch)
treeb670c9e7032d5dc6f1d7f42f4853e4fd10f305b2
parent3ac35cbc2b3d0b08700365983ccde9de498c465d (diff)
downloadsystemd-87a19bfedcd132822974fa096f03e0e0b6de1099.tar.gz
core: use _cleanup_free_ attribute and free_and_replace() macro in method_switch_root()
-rw-r--r--src/core/dbus-manager.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 88e4c6bb95..c52f94c8f2 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -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;