summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-01-14 14:26:37 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-01-16 00:16:02 -0500
commitb7fc42e03a7f52efb8707fabbab841d8b2ffff8c (patch)
tree54445583e995b291d21e7d731ebfbb9cd91600b1 /src
parent8114dedc5910d9a9cec702f6b6658551a0cd9ede (diff)
bus: break reference cycle between bus and messages
Previously (6ee4f99 bus: break reference cycle between bus and messages) I committed the test code, but not the actual fix :)
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-bus.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/libsystemd/sd-bus.c b/src/libsystemd/sd-bus.c
index 6bd1eaa81b..b76221ef9a 100644
--- a/src/libsystemd/sd-bus.c
+++ b/src/libsystemd/sd-bus.c
@@ -1259,12 +1259,25 @@ _public_ sd_bus *sd_bus_ref(sd_bus *bus) {
}
_public_ sd_bus *sd_bus_unref(sd_bus *bus) {
+ unsigned i;
if (!bus)
return NULL;
- if (REFCNT_DEC(bus->n_ref) <= 0)
- bus_free(bus);
+ i = REFCNT_DEC(bus->n_ref);
+ if (i != bus->rqueue_size + bus->wqueue_size)
+ return NULL;
+
+ for (i = 0; i < bus->rqueue_size; i++)
+ if (bus->rqueue[i]->n_ref > 1)
+ return NULL;
+
+ for (i = 0; i < bus->wqueue_size; i++)
+ if (bus->wqueue[i]->n_ref > 1)
+ return NULL;
+
+ /* we are the only holders on the messages */
+ bus_free(bus);
return NULL;
}