pid1: free basic unit information at the very end, before freeing the unit

We would free stuff like the names of the unit first, and then recurse
into other structures to remove the unit from there. Technically this
was OK, since the code did not access the name, but this makes debugging
harder. And if any log messages are added in any of those functions, they
are likely to access u->id and such other basic information about the unit.
So let's move the removal of this "basic" information towards the end
of unit_free().
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-02-15 13:32:59 +01:00
parent 2641f02e23
commit a946fa9bb9
+16 -16
View File
@@ -644,24 +644,8 @@ void unit_free(Unit *u) {
(void) manager_update_failed_units(u->manager, u, false);
set_remove(u->manager->startup_units, u);
free(u->description);
strv_free(u->documentation);
free(u->fragment_path);
free(u->source_path);
strv_free(u->dropin_paths);
free(u->instance);
free(u->job_timeout_reboot_arg);
set_free_free(u->names);
unit_unwatch_all_pids(u);
condition_free_list(u->conditions);
condition_free_list(u->asserts);
free(u->reboot_arg);
unit_ref_unset(&u->slice);
while (u->refs_by_target)
unit_ref_unset(u->refs_by_target);
@@ -677,6 +661,22 @@ void unit_free(Unit *u) {
bpf_program_unref(u->ip_bpf_ingress);
bpf_program_unref(u->ip_bpf_egress);
condition_free_list(u->conditions);
condition_free_list(u->asserts);
free(u->description);
strv_free(u->documentation);
free(u->fragment_path);
free(u->source_path);
strv_free(u->dropin_paths);
free(u->instance);
free(u->job_timeout_reboot_arg);
set_free_free(u->names);
free(u->reboot_arg);
free(u);
}