From a946fa9bb968ac197d7a99970e27388b751dca94 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 14 Feb 2018 00:01:05 +0100 Subject: [PATCH] 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(). --- src/core/unit.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index 0330ae51fd..15cfe84e2f 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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); } -- 2.25.1