From: Alok Barsode <[email protected]>
technology_add_device and technology_add_rfkill should increment
technology refcount. The refcount denotes the total number of devices
and rfkill switches in the technology. Similarly technology_remove_device
and technology_remove_rfkill should decrement technology refcount.
Once the refcount is 0, which means that there are no devices and rfkill
switches in this technology, technology should be freed.
---
src/technology.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/technology.c b/src/technology.c
index 4a85c35..ef9be3e 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -787,8 +787,10 @@ static struct connman_technology *technology_get(enum
connman_service_type type)
return NULL;
technology = technology_find(type);
- if (technology != NULL)
+ if (technology != NULL) {
+ __sync_fetch_and_add(&technology->refcount, 1);
return technology;
+ }
/* First check if we have a driver for this technology type */
for (list = driver_list; list; list = list->next) {
@@ -849,7 +851,7 @@ static void technology_put(struct connman_technology
*technology)
{
DBG("technology %p", technology);
- if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
+ if (__sync_fetch_and_sub(&technology->refcount, 1) > 0)
return;
if (technology->driver) {
@@ -987,6 +989,8 @@ int __connman_technology_remove_device(struct
connman_device *device)
technology->device_list = g_slist_remove(technology->device_list,
device);
+ technology_put(technology);
+
return 0;
}
--
1.7.5.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman