Blame SOURCES/0020-bus-move-BUS_DONT_DESTROY-calls-after-asserts.patch

a3e2b5
From c6903d1b42d1773fda4df6676618489ad760a2a1 Mon Sep 17 00:00:00 2001
a3e2b5
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
a3e2b5
Date: Wed, 18 Jul 2018 12:16:33 +0200
a3e2b5
Subject: [PATCH] bus: move BUS_DONT_DESTROY calls after asserts
a3e2b5
a3e2b5
It's not useful to bump the reference count before checking if the object is
a3e2b5
NULL. Thanks to d40f5cc498 we can do this ;).
a3e2b5
a3e2b5
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1576084,
a3e2b5
https://bugzilla.redhat.com/show_bug.cgi?id=1575340,
a3e2b5
https://bugzilla.redhat.com/show_bug.cgi?id=1575350. I'm not sure why those two
a3e2b5
people hit this code path, while most people don't. At least we won't abort.
a3e2b5
a3e2b5
(cherry picked from commit 7ae8edcd03f74da123298330b76c3fc5425042ef)
a3e2b5
a3e2b5
Resolves: #1610397
a3e2b5
---
a3e2b5
 src/libsystemd/sd-bus/bus-objects.c | 15 ++++++++-------
a3e2b5
 src/libsystemd/sd-bus/sd-bus.c      |  3 ++-
a3e2b5
 2 files changed, 10 insertions(+), 8 deletions(-)
a3e2b5
a3e2b5
diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c
a3e2b5
index 9609834fa9..a18ff88b07 100644
a3e2b5
--- a/src/libsystemd/sd-bus/bus-objects.c
a3e2b5
+++ b/src/libsystemd/sd-bus/bus-objects.c
a3e2b5
@@ -2090,7 +2090,6 @@ _public_ int sd_bus_emit_properties_changed_strv(
a3e2b5
                 const char *interface,
a3e2b5
                 char **names) {
a3e2b5
 
a3e2b5
-        BUS_DONT_DESTROY(bus);
a3e2b5
         bool found_interface = false;
a3e2b5
         char *prefix;
a3e2b5
         int r;
a3e2b5
@@ -2111,6 +2110,8 @@ _public_ int sd_bus_emit_properties_changed_strv(
a3e2b5
         if (names && names[0] == NULL)
a3e2b5
                 return 0;
a3e2b5
 
a3e2b5
+        BUS_DONT_DESTROY(bus);
a3e2b5
+
a3e2b5
         do {
a3e2b5
                 bus->nodes_modified = false;
a3e2b5
 
a3e2b5
@@ -2310,8 +2311,6 @@ static int object_added_append_all(sd_bus *bus, sd_bus_message *m, const char *p
a3e2b5
 }
a3e2b5
 
a3e2b5
 _public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) {
a3e2b5
-        BUS_DONT_DESTROY(bus);
a3e2b5
-
a3e2b5
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
a3e2b5
         struct node *object_manager;
a3e2b5
         int r;
a3e2b5
@@ -2341,6 +2340,8 @@ _public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) {
a3e2b5
         if (r == 0)
a3e2b5
                 return -ESRCH;
a3e2b5
 
a3e2b5
+        BUS_DONT_DESTROY(bus);
a3e2b5
+
a3e2b5
         do {
a3e2b5
                 bus->nodes_modified = false;
a3e2b5
                 m = sd_bus_message_unref(m);
a3e2b5
@@ -2481,8 +2482,6 @@ static int object_removed_append_all(sd_bus *bus, sd_bus_message *m, const char
a3e2b5
 }
a3e2b5
 
a3e2b5
 _public_ int sd_bus_emit_object_removed(sd_bus *bus, const char *path) {
a3e2b5
-        BUS_DONT_DESTROY(bus);
a3e2b5
-
a3e2b5
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
a3e2b5
         struct node *object_manager;
a3e2b5
         int r;
a3e2b5
@@ -2512,6 +2511,8 @@ _public_ int sd_bus_emit_object_removed(sd_bus *bus, const char *path) {
a3e2b5
         if (r == 0)
a3e2b5
                 return -ESRCH;
a3e2b5
 
a3e2b5
+        BUS_DONT_DESTROY(bus);
a3e2b5
+
a3e2b5
         do {
a3e2b5
                 bus->nodes_modified = false;
a3e2b5
                 m = sd_bus_message_unref(m);
a3e2b5
@@ -2645,8 +2646,6 @@ static int interfaces_added_append_one(
a3e2b5
 }
a3e2b5
 
a3e2b5
 _public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces) {
a3e2b5
-        BUS_DONT_DESTROY(bus);
a3e2b5
-
a3e2b5
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
a3e2b5
         struct node *object_manager;
a3e2b5
         char **i;
a3e2b5
@@ -2669,6 +2668,8 @@ _public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, ch
a3e2b5
         if (r == 0)
a3e2b5
                 return -ESRCH;
a3e2b5
 
a3e2b5
+        BUS_DONT_DESTROY(bus);
a3e2b5
+
a3e2b5
         do {
a3e2b5
                 bus->nodes_modified = false;
a3e2b5
                 m = sd_bus_message_unref(m);
a3e2b5
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
a3e2b5
index 089b51a6d9..7f03528b89 100644
a3e2b5
--- a/src/libsystemd/sd-bus/sd-bus.c
a3e2b5
+++ b/src/libsystemd/sd-bus/sd-bus.c
a3e2b5
@@ -2883,7 +2883,6 @@ finish:
a3e2b5
 }
a3e2b5
 
a3e2b5
 static int bus_process_internal(sd_bus *bus, bool hint_priority, int64_t priority, sd_bus_message **ret) {
a3e2b5
-        BUS_DONT_DESTROY(bus);
a3e2b5
         int r;
a3e2b5
 
a3e2b5
         /* Returns 0 when we didn't do anything. This should cause the
a3e2b5
@@ -2899,6 +2898,8 @@ static int bus_process_internal(sd_bus *bus, bool hint_priority, int64_t priorit
a3e2b5
         assert_return(!bus->current_message, -EBUSY);
a3e2b5
         assert(!bus->current_slot);
a3e2b5
 
a3e2b5
+        BUS_DONT_DESTROY(bus);
a3e2b5
+
a3e2b5
         switch (bus->state) {
a3e2b5
 
a3e2b5
         case BUS_UNSET: