From 538b43ae9e3e7592f7f758e70b86bf2d97093bb9 Mon Sep 17 00:00:00 2001 From: Pekka Pessi Date: Thu, 26 Aug 2010 17:26:43 +0300 Subject: [PATCH] ofono: fix add_network() Protect against duplication, remove leak. --- plugins/ofono.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/ofono.c b/plugins/ofono.c index 7d686a3..9e022b9 100644 --- a/plugins/ofono.c +++ b/plugins/ofono.c @@ -654,18 +654,19 @@ static void add_network(struct connman_device *device, const char *path) DBG("device %p path %s", device, path); - network = connman_device_get_network(device, path); + ident = get_ident(path); + + network = connman_device_get_network(device, ident); if (network != NULL) return; - ident = get_ident(path); - - network = connman_network_create(ident, - CONNMAN_NETWORK_TYPE_CELLULAR); + network = connman_network_create(ident, CONNMAN_NETWORK_TYPE_CELLULAR); if (network == NULL) return; - connman_network_set_string(network, "Path", path); + if (connman_network_set_string(network, "Path", path) != 0) + goto error; + connman_network_set_available(network, TRUE); connman_network_set_index(network, -1); @@ -677,7 +678,11 @@ static void add_network(struct connman_device *device, const char *path) if (mnc != NULL) connman_network_set_string(network, "Cellular.MNC", mnc); - connman_device_add_network(device, network); + if (connman_device_add_network(device, network) == 0) + return; + +error: + connman_network_unref(network); } static void add_networks(struct connman_device *device, DBusMessageIter *array) -- 2.7.4