ofono: Fix add_newtork() error path
authordaniel.wagner@bmw-carit.de <daniel.wagner@bmw-carit.de>
Tue, 21 Jun 2011 09:26:05 +0000 (11:26 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 21 Jun 2011 09:54:43 +0000 (11:54 +0200)
After add_network() added the newly created network object
to the network_hash and add_netork() bails out with an
error the network_remove() callback will called from network.c.

Therefore we don't have to free the network object in
the error path of add_network(). It will be removed
by the network_remove() callback.

plugins/ofono.c

index a1c936a5f2870e2d6ab91681ab886bf8cab67477..c24165e6a9bd4d36e16cb3385cbfc62abd219ac5 100644 (file)
@@ -807,7 +807,6 @@ static int add_network(struct connman_device *device,
        struct connman_network *network;
        struct network_info *info;
        char *ident;
-       const char *hash_path;
        dbus_bool_t active = FALSE;
 
        DBG("modem %p device %p path %s", modem, device, path);
@@ -845,17 +844,10 @@ static int add_network(struct connman_device *device,
        info->network = network;
 
        connman_network_set_string(network, "Path", path);
-       hash_path = connman_network_get_string(network, "Path");
-       if (hash_path == NULL) {
-               connman_network_unref(network);
-               g_free(info);
-               return -EIO;
-       }
 
        create_service(network);
 
-       connman_network_ref(network);
-       g_hash_table_insert(network_hash, (char *) hash_path, info);
+       g_hash_table_insert(network_hash, (char *) path, info);
 
        connman_network_set_available(network, TRUE);
        connman_network_set_index(network, -1);
@@ -884,7 +876,7 @@ static int add_network(struct connman_device *device,
                        dbus_message_iter_get_basic(&value, &type);
                        if (g_strcmp0(type, "internet") != 0) {
                                DBG("path %p type %s", path, type);
-                               goto error;
+                               return -EIO;
                        }
                } else if (g_str_equal(key, "Settings"))
                        update_ipv4_settings(&value, info);
@@ -897,19 +889,13 @@ static int add_network(struct connman_device *device,
        }
 
        if (connman_device_add_network(device, network) != 0)
-               goto error;
+               return -EIO;
 
        /* Connect only if requested to do so */
        if (active && connman_network_get_connecting(network) == TRUE)
                set_connected(info, active);
 
        return 0;
-
-error:
-       connman_network_unregister(network);
-       connman_network_unref(network);
-       g_hash_table_remove(network_hash, hash_path);
-       return -EIO;
 }
 
 static void check_networks_reply(DBusPendingCall *call, void *user_data)