valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0755-pid1-free-basic-unit-information-at-the-very-end-bef.patch

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