Package: systemd / 232-25+deb9u12

core-make-unit_free-accept-NULL-pointers.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
From: Lennart Poettering <lennart@poettering.net>
Date: Mon, 28 Nov 2016 19:41:20 +0100
Subject: core: make unit_free() accept NULL pointers

We generally try to make our destructors robust regarding NULL pointers, much
in the same way as glibc's free(). Do this also for unit_free().

Follow-up for #4748.

(cherry picked from commit c9d5c9c0e19eea79ca0f09fe58e5c0b76b8001e2)
---
 src/core/device.c | 2 +-
 src/core/mount.c  | 2 +-
 src/core/swap.c   | 2 +-
 src/core/unit.c   | 3 ++-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/core/device.c b/src/core/device.c
index 425779d..498351a 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -365,7 +365,7 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa
 fail:
         log_unit_warning_errno(u, r, "Failed to set up device unit: %m");
 
-        if (delete && u)
+        if (delete)
                 unit_free(u);
 
         return r;
diff --git a/src/core/mount.c b/src/core/mount.c
index 53ddc36..b3831f0 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -1513,7 +1513,7 @@ static int mount_setup_unit(
 fail:
         log_warning_errno(r, "Failed to set up mount unit: %m");
 
-        if (delete && u)
+        if (delete)
                 unit_free(u);
 
         return r;
diff --git a/src/core/swap.c b/src/core/swap.c
index 2228a25..b52c73a 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -420,7 +420,7 @@ static int swap_setup_unit(
 fail:
         log_unit_warning_errno(u, r, "Failed to load swap unit: %m");
 
-        if (delete && u)
+        if (delete)
                 unit_free(u);
 
         return r;
diff --git a/src/core/unit.c b/src/core/unit.c
index fa1f3d9..0ab6d92 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -518,7 +518,8 @@ void unit_free(Unit *u) {
         Iterator i;
         char *t;
 
-        assert(u);
+        if (!u)
+                return;
 
         if (u->transient_file)
                 fclose(u->transient_file);