bus: move BUS_DONT_DESTROY calls after asserts
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 18 Jul 2018 10:16:33 +0000 (12:16 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 18 Jul 2018 10:16:33 +0000 (12:16 +0200)
It's not useful to bump the reference count before checking if the object is
NULL. Thanks to d40f5cc498 we can do this ;).

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1576084,
https://bugzilla.redhat.com/show_bug.cgi?id=1575340,
https://bugzilla.redhat.com/show_bug.cgi?id=1575350. I'm not sure why those two
people hit this code path, while most people don't. At least we won't abort.

src/libsystemd/sd-bus/bus-objects.c
src/libsystemd/sd-bus/sd-bus.c

index 0d4e75c..f5f6795 100644 (file)
@@ -2088,7 +2088,6 @@ _public_ int sd_bus_emit_properties_changed_strv(
                 const char *interface,
                 char **names) {
 
-        BUS_DONT_DESTROY(bus);
         bool found_interface = false;
         char *prefix;
         int r;
@@ -2109,6 +2108,8 @@ _public_ int sd_bus_emit_properties_changed_strv(
         if (names && names[0] == NULL)
                 return 0;
 
+        BUS_DONT_DESTROY(bus);
+
         do {
                 bus->nodes_modified = false;
 
@@ -2308,8 +2309,6 @@ static int object_added_append_all(sd_bus *bus, sd_bus_message *m, const char *p
 }
 
 _public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) {
-        BUS_DONT_DESTROY(bus);
-
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
         struct node *object_manager;
         int r;
@@ -2339,6 +2338,8 @@ _public_ int sd_bus_emit_object_added(sd_bus *bus, const char *path) {
         if (r == 0)
                 return -ESRCH;
 
+        BUS_DONT_DESTROY(bus);
+
         do {
                 bus->nodes_modified = false;
                 m = sd_bus_message_unref(m);
@@ -2479,8 +2480,6 @@ static int object_removed_append_all(sd_bus *bus, sd_bus_message *m, const char
 }
 
 _public_ int sd_bus_emit_object_removed(sd_bus *bus, const char *path) {
-        BUS_DONT_DESTROY(bus);
-
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
         struct node *object_manager;
         int r;
@@ -2510,6 +2509,8 @@ _public_ int sd_bus_emit_object_removed(sd_bus *bus, const char *path) {
         if (r == 0)
                 return -ESRCH;
 
+        BUS_DONT_DESTROY(bus);
+
         do {
                 bus->nodes_modified = false;
                 m = sd_bus_message_unref(m);
@@ -2643,8 +2644,6 @@ static int interfaces_added_append_one(
 }
 
 _public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces) {
-        BUS_DONT_DESTROY(bus);
-
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
         struct node *object_manager;
         char **i;
@@ -2667,6 +2666,8 @@ _public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, ch
         if (r == 0)
                 return -ESRCH;
 
+        BUS_DONT_DESTROY(bus);
+
         do {
                 bus->nodes_modified = false;
                 m = sd_bus_message_unref(m);
index deb6645..689cbf7 100644 (file)
@@ -2884,7 +2884,6 @@ finish:
 }
 
 static int bus_process_internal(sd_bus *bus, bool hint_priority, int64_t priority, sd_bus_message **ret) {
-        BUS_DONT_DESTROY(bus);
         int r;
 
         /* Returns 0 when we didn't do anything. This should cause the
@@ -2900,6 +2899,8 @@ static int bus_process_internal(sd_bus *bus, bool hint_priority, int64_t priorit
         assert_return(!bus->current_message, -EBUSY);
         assert(!bus->current_slot);
 
+        BUS_DONT_DESTROY(bus);
+
         switch (bus->state) {
 
         case BUS_UNSET: