From 2e7e8e34aa1acbe3c47b8931d67a4b6dba3d5652 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 17 Jul 2018 17:53:22 +0900 Subject: [PATCH] sd-bus: make bus_slot_disconnect() also unref the slot object This makes bus_slot_disconnect() unref the slot object from bus when `unref == true` and it is floating, as the function removes the reference from the relevant bus object. This reverts 20d4ee2cbc21e0c4d2dd6c01d5a18a4cf0d98222, as it introduces #9604. Fixes #9604. --- src/libsystemd/sd-bus/bus-slot.c | 11 +++++------ src/libsystemd/sd-bus/bus-slot.h | 2 +- src/libsystemd/sd-bus/sd-bus.c | 27 +++++++++------------------ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 17ea8f2ed1..19ef692e7f 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -48,7 +48,7 @@ _public_ sd_bus_slot* sd_bus_slot_ref(sd_bus_slot *slot) { return slot; } -void bus_slot_disconnect(sd_bus_slot *slot) { +void bus_slot_disconnect(sd_bus_slot *slot, bool unref) { sd_bus *bus; assert(slot); @@ -79,10 +79,7 @@ void bus_slot_disconnect(sd_bus_slot *slot) { (void) bus_remove_match_internal(slot->bus, slot->match_callback.match_string); if (slot->match_callback.install_slot) { - if (slot->match_callback.install_slot->bus) { - bus_slot_disconnect(slot->match_callback.install_slot); - sd_bus_slot_unref(slot->match_callback.install_slot); - } + bus_slot_disconnect(slot->match_callback.install_slot, true); slot->match_callback.install_slot = sd_bus_slot_unref(slot->match_callback.install_slot); } @@ -186,6 +183,8 @@ void bus_slot_disconnect(sd_bus_slot *slot) { if (!slot->floating) sd_bus_unref(bus); + else if (unref) + sd_bus_slot_unref(slot); } _public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) { @@ -200,7 +199,7 @@ _public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) { return NULL; } - bus_slot_disconnect(slot); + bus_slot_disconnect(slot, false); if (slot->destroy_callback) slot->destroy_callback(slot->userdata); diff --git a/src/libsystemd/sd-bus/bus-slot.h b/src/libsystemd/sd-bus/bus-slot.h index 555afac9a6..48eb0453dc 100644 --- a/src/libsystemd/sd-bus/bus-slot.h +++ b/src/libsystemd/sd-bus/bus-slot.h @@ -7,4 +7,4 @@ sd_bus_slot *bus_slot_allocate(sd_bus *bus, bool floating, BusSlotType type, size_t extra, void *userdata); -void bus_slot_disconnect(sd_bus_slot *slot); +void bus_slot_disconnect(sd_bus_slot *slot, bool unref); diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 7787caaa4f..a87f4625ec 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -178,8 +178,7 @@ static sd_bus* bus_free(sd_bus *b) { * apps, but are dead. */ assert(s->floating); - bus_slot_disconnect(s); - sd_bus_slot_unref(s); + bus_slot_disconnect(s, true); } if (b->default_bus_ptr) @@ -2360,10 +2359,8 @@ static int process_timeout(sd_bus *bus) { bus->current_slot = NULL; bus->current_message = NULL; - if (slot->floating) { - bus_slot_disconnect(slot); - sd_bus_slot_unref(slot); - } + if (slot->floating) + bus_slot_disconnect(slot, true); sd_bus_slot_unref(slot); @@ -2465,10 +2462,8 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) { bus->current_handler = NULL; bus->current_slot = NULL; - if (slot->floating) { - bus_slot_disconnect(slot); - sd_bus_slot_unref(slot); - } + if (slot->floating) + bus_slot_disconnect(slot, true); sd_bus_slot_unref(slot); @@ -2810,10 +2805,8 @@ static int process_closing_reply_callback(sd_bus *bus, struct reply_callback *c) bus->current_slot = NULL; bus->current_message = NULL; - if (slot->floating) { - bus_slot_disconnect(slot); - sd_bus_slot_unref(slot); - } + if (slot->floating) + bus_slot_disconnect(slot, true); sd_bus_slot_unref(slot); @@ -3168,10 +3161,8 @@ static int add_match_callback( r = 1; } - if (failed && match_slot->floating) { - bus_slot_disconnect(match_slot); - sd_bus_slot_unref(match_slot); - } + if (failed && match_slot->floating) + bus_slot_disconnect(match_slot, true); sd_bus_slot_unref(match_slot);