ipconfig: Add function to clear ipaddress information
[platform/upstream/connman.git] / src / tethering.c
index 2d66cda..f3d67df 100644 (file)
@@ -198,14 +198,18 @@ void __connman_tethering_set_enabled(void)
                return;
 
        err = __connman_bridge_create(BRIDGE_NAME);
-       if (err < 0)
+       if (err < 0) {
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
+       }
 
        index = connman_inet_ifindex(BRIDGE_NAME);
        dhcp_ippool = __connman_ippool_create(index, 2, 252,
                                                tethering_restart, NULL);
        if (dhcp_ippool == NULL) {
                connman_error("Fail to create IP pool");
+               __connman_bridge_remove(BRIDGE_NAME);
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
        }
 
@@ -217,7 +221,9 @@ void __connman_tethering_set_enabled(void)
 
        err = __connman_bridge_enable(BRIDGE_NAME, gateway, broadcast);
        if (err < 0 && err != -EALREADY) {
+               __connman_ippool_unref(dhcp_ippool);
                __connman_bridge_remove(BRIDGE_NAME);
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
        }
 
@@ -234,7 +240,9 @@ void __connman_tethering_set_enabled(void)
                                                24 * 3600, dns);
        if (tethering_dhcp_server == NULL) {
                __connman_bridge_disable(BRIDGE_NAME);
+               __connman_ippool_unref(dhcp_ippool);
                __connman_bridge_remove(BRIDGE_NAME);
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
        }