From 87a19bfedcd132822974fa096f03e0e0b6de1099 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 15 Mar 2019 18:59:31 +0900 Subject: [PATCH] core: use _cleanup_free_ attribute and free_and_replace() macro in method_switch_root() --- src/core/dbus-manager.c | 13 ++++--------- 1 file 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;