]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: free basic unit information at the very end, before freeing the unit
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 13 Feb 2018 23:01:05 +0000 (00:01 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 Feb 2018 12:32:59 +0000 (13:32 +0100)
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

index 0330ae51fdd70152a7ba563768b3d72a71e7b4da..15cfe84e2f71f48be735032d29d6560db9e014e0 100644 (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);
 }