Pablo Greco 48fc63
From 20d684011c93bed4b45c736ac1f9104983a090dc Mon Sep 17 00:00:00 2001
Pablo Greco 48fc63
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Pablo Greco 48fc63
Date: Wed, 14 Feb 2018 00:01:05 +0100
Pablo Greco 48fc63
Subject: [PATCH] pid1: free basic unit information at the very end, before
Pablo Greco 48fc63
 freeing the unit
Pablo Greco 48fc63
Pablo Greco 48fc63
We would free stuff like the names of the unit first, and then recurse
Pablo Greco 48fc63
into other structures to remove the unit from there. Technically this
Pablo Greco 48fc63
was OK, since the code did not access the name, but this makes debugging
Pablo Greco 48fc63
harder. And if any log messages are added in any of those functions, they
Pablo Greco 48fc63
are likely to access u->id and such other basic information about the unit.
Pablo Greco 48fc63
So let's move the removal of this "basic" information towards the end
Pablo Greco 48fc63
of unit_free().
Pablo Greco 48fc63
Pablo Greco 48fc63
(cherry picked from commit a946fa9bb968ac197d7a99970e27388b751dca94)
Pablo Greco 48fc63
(cherry picked from commit 42a93a826cd726d1e4d3ea2c8cb347cec2f0dabe)
Pablo Greco 48fc63
Pablo Greco 48fc63
Related: #1729228
Pablo Greco 48fc63
---
Pablo Greco 48fc63
 src/core/unit.c | 18 +++++++++---------
Pablo Greco 48fc63
 1 file changed, 9 insertions(+), 9 deletions(-)
Pablo Greco 48fc63
Pablo Greco 48fc63
diff --git a/src/core/unit.c b/src/core/unit.c
Pablo Greco 48fc63
index 2204be26d2..63f00acc0a 100644
Pablo Greco 48fc63
--- a/src/core/unit.c
Pablo Greco 48fc63
+++ b/src/core/unit.c
Pablo Greco 48fc63
@@ -537,6 +537,15 @@ void unit_free(Unit *u) {
Pablo Greco 48fc63
         set_remove(u->manager->failed_units, u);
Pablo Greco 48fc63
         set_remove(u->manager->startup_units, u);
Pablo Greco 48fc63
 
Pablo Greco 48fc63
+        unit_unwatch_all_pids(u);
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+        unit_ref_unset(&u->slice);
Pablo Greco 48fc63
+        while (u->refs_by_target)
Pablo Greco 48fc63
+                unit_ref_unset(u->refs_by_target);
Pablo Greco 48fc63
+
Pablo Greco 48fc63
+        condition_free_list(u->conditions);
Pablo Greco 48fc63
+        condition_free_list(u->asserts);
Pablo Greco 48fc63
+
Pablo Greco 48fc63
         free(u->description);
Pablo Greco 48fc63
         strv_free(u->documentation);
Pablo Greco 48fc63
         free(u->fragment_path);
Pablo Greco 48fc63
@@ -548,15 +557,6 @@ void unit_free(Unit *u) {
Pablo Greco 48fc63
 
Pablo Greco 48fc63
         set_free_free(u->names);
Pablo Greco 48fc63
 
Pablo Greco 48fc63
-        unit_unwatch_all_pids(u);
Pablo Greco 48fc63
-
Pablo Greco 48fc63
-        condition_free_list(u->conditions);
Pablo Greco 48fc63
-        condition_free_list(u->asserts);
Pablo Greco 48fc63
-
Pablo Greco 48fc63
-        unit_ref_unset(&u->slice);
Pablo Greco 48fc63
-        while (u->refs_by_target)
Pablo Greco 48fc63
-                unit_ref_unset(u->refs_by_target);
Pablo Greco 48fc63
-
Pablo Greco 48fc63
         free(u);
Pablo Greco 48fc63
 }
Pablo Greco 48fc63