]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: make add match method callback slot "floating" 9132/head
authorLennart Poettering <lennart@poettering.net>
Wed, 30 May 2018 14:35:36 +0000 (16:35 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 30 May 2018 15:34:34 +0000 (17:34 +0200)
When we allocate an asynchronous match object we will allocate an
asynchronous bus call object to install the match server side.
Previously the call slot would be created as regular slot, i.e.
non-floating which meant installing the match even if it was itself
floating would result in a non-floating slot to be created internally,
which ultimately would mean the sd_bus object would be referenced by it,
and thus never be freed.

Let's fix that by making the match method callback floating in any case
as we have no interest in leaving the bus allocated beyond the match
slot.

Fixes: #8551
src/libsystemd/sd-bus/sd-bus.c

index c1974dabe79c1d2a6ed3d8ad7b531ac4b3de4d23..8ecb381586bec4bcabe4619336a503b02e2954c4 100644 (file)
@@ -3227,13 +3227,21 @@ static int bus_add_match_full(
                                 goto finish;
                         }
 
-                        if (asynchronous)
+                        if (asynchronous) {
                                 r = bus_add_match_internal_async(bus,
                                                                  &s->match_callback.install_slot,
                                                                  s->match_callback.match_string,
                                                                  add_match_callback,
                                                                  s);
-                        else
+
+                                if (r < 0)
+                                        return r;
+
+                                /* Make the slot of the match call floating now. We need the reference, but we don't
+                                 * want that this match pins the bus object, hence we first create it non-floating, but
+                                 * then make it floating. */
+                                r = sd_bus_slot_set_floating(s->match_callback.install_slot, true);
+                        } else
                                 r = bus_add_match_internal(bus, s->match_callback.match_string);
                         if (r < 0)
                                 goto finish;