From 1e58120a5ca51d01c334ad467a357599e61b4c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Date: Tue, 24 Sep 2013 19:45:29 -0300 Subject: [PATCH] bluetooth: Create a function to remove only one adapter object --- src/modules/bluetooth/bluez5-util.c | 34 ++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c index 2a5b1ab4c..9e1495131 100644 --- a/src/modules/bluetooth/bluez5-util.c +++ b/src/modules/bluetooth/bluez5-util.c @@ -364,6 +364,33 @@ static pa_bluetooth_adapter* adapter_create(pa_bluetooth_discovery *y, const cha return a; } +static void adapter_free(pa_bluetooth_adapter *a) { + pa_bluetooth_device *d; + void *state; + + pa_assert(a); + pa_assert(a->discovery); + + PA_HASHMAP_FOREACH(d, a->discovery->devices, state) + if (d->adapter == a) + d->adapter = NULL; + + pa_xfree(a->path); + pa_xfree(a->address); + pa_xfree(a); +} + +static void adapter_remove(pa_bluetooth_discovery *y, const char *path) { + pa_bluetooth_adapter *a; + + if (!(a = pa_hashmap_remove(y->adapters, path))) + pa_log_warn("Unknown adapter removed %s", path); + else { + pa_log_debug("Adapter %s removed", path); + adapter_free(a); + } +} + static void adapter_remove_all(pa_bluetooth_discovery *y) { pa_bluetooth_adapter *a; @@ -371,11 +398,8 @@ static void adapter_remove_all(pa_bluetooth_discovery *y) { /* When this function is called all devices have already been freed */ - while ((a = pa_hashmap_steal_first(y->adapters))) { - pa_xfree(a->path); - pa_xfree(a->address); - pa_xfree(a); - } + while ((a = pa_hashmap_steal_first(y->adapters))) + adapter_free(a); } static void get_managed_objects_reply(DBusPendingCall *pending, void *userdata) {