From 38f514409ac2f98b04a15c6e47a659a43618bd3b Mon Sep 17 00:00:00 2001 From: David Tardon Date: Wed, 30 Nov 2022 16:42:08 +0100 Subject: machine: use _cleanup_ in machine_new --- src/machine/machine.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/machine/machine.c b/src/machine/machine.c index de7b20ff2d..ca43c977b0 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -33,8 +33,10 @@ #include "unit-name.h" #include "user-util.h" +DEFINE_TRIVIAL_CLEANUP_FUNC(Machine*, machine_free); + Machine* machine_new(Manager *manager, MachineClass class, const char *name) { - Machine *m; + _cleanup_(machine_freep) Machine *m = NULL; assert(manager); assert(class < _MACHINE_CLASS_MAX); @@ -50,27 +52,22 @@ Machine* machine_new(Manager *manager, MachineClass class, const char *name) { m->name = strdup(name); if (!m->name) - goto fail; + return NULL; if (class != MACHINE_HOST) { m->state_file = path_join("/run/systemd/machines", m->name); if (!m->state_file) - goto fail; + return NULL; } m->class = class; if (hashmap_put(manager->machines, m->name, m) < 0) - goto fail; + return NULL; m->manager = manager; - return m; - -fail: - free(m->state_file); - free(m->name); - return mfree(m); + return TAKE_PTR(m); } Machine* machine_free(Machine *m) { -- cgit v1.2.1