Fix reference counting with multiple networks with same SSID
authorMarcel Holtmann <marcel@holtmann.org>
Fri, 17 Jul 2009 12:51:52 +0000 (14:51 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 17 Jul 2009 12:51:52 +0000 (14:51 +0200)
src/connman.h
src/profile.c
src/service.c

index 0ac1c71..b3aa487 100644 (file)
@@ -254,9 +254,11 @@ void __connman_service_put(struct connman_service *service);
 
 struct connman_service *__connman_service_lookup_from_device(struct connman_device *device);
 struct connman_service *__connman_service_create_from_device(struct connman_device *device);
+void __connman_service_remove_from_device(struct connman_device *device);
 
 struct connman_service *__connman_service_lookup_from_network(struct connman_network *network);
 struct connman_service *__connman_service_create_from_network(struct connman_network *network);
+void __connman_service_remove_from_network(struct connman_network *network);
 
 unsigned int __connman_service_get_order(struct connman_service *service);
 
index 1fd3068..ca316ed 100644 (file)
@@ -133,17 +133,9 @@ int __connman_profile_add_device(struct connman_device *device)
 
 int __connman_profile_remove_device(struct connman_device *device)
 {
-       struct connman_service *service;
-
        DBG("device %p", device);
 
-       service = __connman_service_lookup_from_device(device);
-       if (service == NULL)
-               return -EINVAL;
-
-       __connman_service_disconnect(service);
-
-       __connman_service_put(service);
+       __connman_service_remove_from_device(device);
 
        return 0;
 }
@@ -163,17 +155,9 @@ int __connman_profile_add_network(struct connman_network *network)
 
 int __connman_profile_remove_network(struct connman_network *network)
 {
-       struct connman_service *service;
-
        DBG("network %p", network);
 
-       service = __connman_service_lookup_from_network(network);
-       if (service == NULL)
-               return -EINVAL;
-
-       __connman_service_disconnect(service);
-
-       __connman_service_put(service);
+       __connman_service_remove_from_network(network);
 
        return 0;
 }
index 1da6aa3..014ec9e 100644 (file)
@@ -814,11 +814,11 @@ void __connman_service_put(struct connman_service *service)
 
                        reply_pending(service, EIO);
 
+                       __connman_service_disconnect(service);
+
                        if (service->network != NULL) {
                                connman_network_unref(service->network);
                                service->network = NULL;
-
-                               interval = 5;
                        }
 
                        service->state = CONNMAN_SERVICE_STATE_FAILURE;
@@ -1512,6 +1512,17 @@ done:
        return service;
 }
 
+void __connman_service_remove_from_device(struct connman_device *device)
+{
+       struct connman_service *service;
+
+       service = __connman_service_lookup_from_device(device);
+       if (service == NULL)
+               return;
+
+       __connman_service_put(service);
+}
+
 /**
  * __connman_service_lookup_from_network:
  * @network: network structure
@@ -1683,11 +1694,11 @@ struct connman_service *__connman_service_create_from_network(struct connman_net
                                service->timeout = 0;
                        }
 
-                       connman_service_ref(service);
-
                        set_idle(service);
                }
 
+               connman_service_ref(service);
+
                update_from_network(service, network);
                return service;
        }
@@ -1737,6 +1748,17 @@ done:
        return service;
 }
 
+void __connman_service_remove_from_network(struct connman_network *network)
+{
+       struct connman_service *service;
+
+       service = __connman_service_lookup_from_network(network);
+       if (service == NULL)
+               return;
+
+       __connman_service_put(service);
+}
+
 static int service_load(struct connman_service *service)
 {
        GKeyFile *keyfile;