1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

Make sure that keys are properly removed from hashmap

This is a speculative fix for https://bugzilla.redhat.com/show_bug.cgi?id=1088865.
Even though I cannot find a code path that where this would be
an issue, for consistency, if we assume that cgroup_path might have
been set before we got to unit_deserialize, we should make sure that
the unit is removed from the hashmap before we free the key. This seems
to be the only place where the key could be prematurely freed, leading to
hashmap corruption.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2014-04-17 22:12:25 -04:00
parent de0671ee7f
commit 4e595329a9
Notes: Lennart Poettering 2014-05-19 02:01:15 +09:00
Backport: bugfix

View File

@ -2488,10 +2488,18 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
if (!s)
return -ENOMEM;
free(u->cgroup_path);
u->cgroup_path = s;
if (u->cgroup_path) {
void *p;
p = hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
log_info("Removing cgroup_path %s from hashmap (%p)",
u->cgroup_path, p);
free(u->cgroup_path);
}
u->cgroup_path = s;
assert(hashmap_put(u->manager->cgroup_unit, s, u) == 1);
continue;
}