From 354f62cf3ca0d328a4e81756008e64c96dc9f29b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 7 Aug 2018 10:11:56 +0900 Subject: [PATCH] machine: use free_and_replace() and TAKE_PTR() --- src/machine/machine.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/machine/machine.c b/src/machine/machine.c index b645f614c41..6ab33d3bea9 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -328,14 +328,13 @@ int machine_load(Machine *m) { } static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_error *error) { - int r = 0; - assert(m); assert(m->class != MACHINE_HOST); if (!m->unit) { - _cleanup_free_ char *escaped = NULL; - char *scope, *description, *job = NULL; + _cleanup_free_ char *escaped = NULL, *scope = NULL; + char *description, *job = NULL; + int r; escaped = unit_name_escape(m->name); if (!escaped) @@ -348,22 +347,17 @@ static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_er description = strjoina(m->class == MACHINE_VM ? "Virtual Machine " : "Container ", m->name); r = manager_start_scope(m->manager, scope, m->leader, SPECIAL_MACHINE_SLICE, description, properties, error, &job); - if (r < 0) { - log_error("Failed to start machine scope: %s", bus_error_message(error, r)); - free(scope); - return r; - } else { - m->unit = scope; - - free(m->scope_job); - m->scope_job = job; - } + if (r < 0) + return log_error_errno(r, "Failed to start machine scope: %s", bus_error_message(error, r)); + + m->unit = TAKE_PTR(scope); + free_and_replace(m->scope_job, job); } if (m->unit) hashmap_put(m->manager->machine_units, m->unit, m); - return r; + return 0; } int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) { @@ -417,15 +411,10 @@ static int machine_stop_scope(Machine *m) { return 0; r = manager_stop_unit(m->manager, m->unit, &error, &job); - if (r < 0) { - log_error("Failed to stop machine scope: %s", bus_error_message(&error, r)); - return r; - } - - free(m->scope_job); - m->scope_job = job; + if (r < 0) + return log_error_errno(r, "Failed to stop machine scope: %s", bus_error_message(&error, r)); - return 0; + return free_and_replace(m->scope_job, job); } int machine_stop(Machine *m) { -- 2.39.2