summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlok Barsode <alok.barsode@linux.intel.com>2012-01-25 14:16:41 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2012-02-01 00:19:28 +0100
commitfc29a97acd4bcbd37ff9001e7651e54a246417ad (patch)
tree66ec83cec68e890ad4a903b38d2a3b167b36e4bb /src
parentaeeb2e24ab65a9b0b174231ca602b517564bdef0 (diff)
downloadconnman-fc29a97acd4bcbd37ff9001e7651e54a246417ad.tar.gz
connman-fc29a97acd4bcbd37ff9001e7651e54a246417ad.tar.bz2
connman-fc29a97acd4bcbd37ff9001e7651e54a246417ad.zip
technology: Fix technology refcounting
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.
Diffstat (limited to 'src')
-rw-r--r--src/technology.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/technology.c b/src/technology.c
index c08554b3..c208b954 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -786,8 +786,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) {
@@ -848,7 +850,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) {
@@ -986,6 +988,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;
}