summaryrefslogtreecommitdiff
path: root/src/machine/machined.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-12-07 16:47:20 +0100
committerLennart Poettering <lennart@poettering.net>2018-12-15 12:10:19 +0100
commit5be61bead5e618d51a81e4f5bf3604faff9b0b31 (patch)
treed931dc74cfcbd1ef5858d17e91194b8f41bd3633 /src/machine/machined.c
parentf079c3727c9b23cb71ff862d66f8c31246ca3326 (diff)
downloadsystemd-5be61bead5e618d51a81e4f5bf3604faff9b0b31.tar.gz
machined: fix memory corruption
Let's make sure the first hashmap we destroy also frees all machines, because otherwise when freeing the other hashmaps we'll try to deregister the contained machines from the hashmaps already destroyed.
Diffstat (limited to 'src/machine/machined.c')
-rw-r--r--src/machine/machined.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/machine/machined.c b/src/machine/machined.c
index dec2164bb0..3ae57182dc 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -25,8 +25,7 @@
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);
+DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(machine_hash_ops, char, string_hash_func, string_compare_func, Machine, machine_free);
static int manager_new(Manager **ret) {
_cleanup_(manager_unrefp) Manager *m = NULL;
@@ -38,9 +37,9 @@ static int manager_new(Manager **ret) {
if (!m)
return -ENOMEM;
- m->machines = hashmap_new(&string_hash_ops);
+ m->machines = hashmap_new(&machine_hash_ops);
m->machine_units = hashmap_new(&string_hash_ops);
- m->machine_leaders = hashmap_new(&machine_hash_ops);
+ m->machine_leaders = hashmap_new(NULL);
if (!m->machines || !m->machine_units || !m->machine_leaders)
return -ENOMEM;
@@ -72,7 +71,7 @@ static Manager* manager_unref(Manager *m) {
assert(m->n_operations == 0);
- hashmap_free(m->machines);
+ hashmap_free(m->machines); /* This will free all machines, so that the machine_units/machine_leaders is empty */
hashmap_free(m->machine_units);
hashmap_free(m->machine_leaders);
hashmap_free(m->image_cache);