From: Zbigniew Jędrzejewski-Szmek Date: Tue, 13 Feb 2018 23:01:05 +0000 (+0100) Subject: pid1: free basic unit information at the very end, before freeing the unit X-Git-Tag: v238~97^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a946fa9bb968ac197d7a99970e27388b751dca94;p=thirdparty%2Fsystemd.git 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(). --- diff --git a/src/core/unit.c b/src/core/unit.c index 0330ae51fdd..15cfe84e2f7 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); }