From: Yu Watanabe Date: Wed, 28 Nov 2018 13:55:13 +0000 (+0900) Subject: machine: introduce machine_hash_ops and use it X-Git-Tag: v240~151^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb1a05d6f34b6f17ac1b6b49c93ec0f8f97dfce7;p=thirdparty%2Fsystemd.git machine: introduce machine_hash_ops and use it --- diff --git a/src/machine/machine.c b/src/machine/machine.c index e114541b3f0..c76dfc18464 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -70,8 +70,9 @@ fail: return mfree(m); } -void machine_free(Machine *m) { - assert(m); +Machine* machine_free(Machine *m) { + if (!m) + return NULL; while (m->operations) operation_free(m->operations); @@ -98,7 +99,7 @@ void machine_free(Machine *m) { free(m->service); free(m->root_directory); free(m->netif); - free(m); + return mfree(m); } int machine_save(Machine *m) { diff --git a/src/machine/machine.h b/src/machine/machine.h index 967c11039b7..31527d029b2 100644 --- a/src/machine/machine.h +++ b/src/machine/machine.h @@ -65,7 +65,7 @@ struct Machine { }; Machine* machine_new(Manager *manager, MachineClass class, const char *name); -void machine_free(Machine *m); +Machine* machine_free(Machine *m); bool machine_may_gc(Machine *m, bool drop_not_started); void machine_add_to_gc_queue(Machine *m); int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error); diff --git a/src/machine/machined.c b/src/machine/machined.c index 6742722d0dd..dec2164bb04 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -25,6 +25,9 @@ static Manager* manager_unref(Manager *m); DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref); +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(machine_hash_ops, void, trivial_hash_func, trivial_compare_func, + Machine, machine_free); + static int manager_new(Manager **ret) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; @@ -37,7 +40,7 @@ static int manager_new(Manager **ret) { m->machines = hashmap_new(&string_hash_ops); m->machine_units = hashmap_new(&string_hash_ops); - m->machine_leaders = hashmap_new(NULL); + m->machine_leaders = hashmap_new(&machine_hash_ops); if (!m->machines || !m->machine_units || !m->machine_leaders) return -ENOMEM; @@ -61,8 +64,6 @@ static int manager_new(Manager **ret) { } static Manager* manager_unref(Manager *m) { - Machine *machine; - if (!m) return NULL; @@ -71,9 +72,6 @@ static Manager* manager_unref(Manager *m) { assert(m->n_operations == 0); - while ((machine = hashmap_first(m->machines))) - machine_free(machine); - hashmap_free(m->machines); hashmap_free(m->machine_units); hashmap_free(m->machine_leaders);