Fixed memory leaks
[platform/core/connectivity/net-config.git] / src / network-state.c
index 61c5242..bd6c95a 100755 (executable)
@@ -560,7 +560,8 @@ static char *__netconfig_get_preferred_ipv6_address(char *profile)
                        while (g_variant_iter_loop(sub_iter, "{sv}", &sub_key, &variant)) {
                                if (g_strcmp0(sub_key, "Address") == 0) {
                                        value = g_variant_get_string(variant, NULL);
-                                       preferred_address6 = g_strdup(value);
+                                       if (!preferred_address6)
+                                               preferred_address6 = g_strdup(value);
                                }
                        }
                        g_variant_iter_free(sub_iter);
@@ -743,6 +744,7 @@ static void __netconfig_update_default_connection_info(void)
                }
 
                params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+               g_variant_builder_unref(builder);
 
                netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
                                                   NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
@@ -786,6 +788,8 @@ static void __netconfig_update_default_connection_info(void)
                                                   params);
                netconfig_set_vconf_int("memory/private/wifi/frequency", 0);
 
+               g_variant_builder_unref(builder);
+
                DBG("Successfully clear IP and PROXY up");
 
        } else if (profile != NULL) {
@@ -896,6 +900,8 @@ static void __netconfig_update_default_connection_info(void)
                                                   NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
                                                   params);
 
+               g_variant_builder_unref(builder);
+
                DBG("Successfully update default network configuration");
        }
 
@@ -1256,7 +1262,8 @@ char *netconfig_get_ifname(const char *profile)
                        while (g_variant_iter_loop(next, "{sv}", &key1, &variant)) {
                                if (g_strcmp0(key1, "Interface") == 0) {
                                        value = g_variant_get_string(variant, NULL);
-                                       ifname = g_strdup(value);
+                                       if (!ifname)
+                                               ifname = g_strdup(value);
                                        g_free(key1);
                                        g_variant_unref(variant);
                                        break;
@@ -1293,10 +1300,6 @@ static gboolean handle_add_route(
        gchar *const args[] = { "/sbin/route", "add", "-net", ip_addr, gw_str,
                "netmask", netmask, "dev", interface, NULL };
        gchar *const envs[] = { NULL };
-       const gchar* buf = NULL;
-       gchar* ch = NULL;
-       int prefix_len = 0;
-       int pos = 0;
 
        DBG("ip_addr(%s), netmask(%s), interface(%s), gateway(%s)", ip_addr, netmask, interface, gateway);
 
@@ -1305,13 +1308,13 @@ static gboolean handle_add_route(
                if (ip_addr == NULL || netmask == NULL || interface == NULL) {
                        ERR("Invalid parameter");
                        netconfig_error_invalid_parameter(context);
-                       return FALSE;
+                       return TRUE;
                }
 
                if (netconfig_execute_file(path, args, envs) < 0) {
                        DBG("Failed to add a new route");
                        netconfig_error_permission_denied(context);
-                       return FALSE;
+                       return TRUE;
                }
 
                break;
@@ -1319,29 +1322,19 @@ static gboolean handle_add_route(
                if (ip_addr == NULL || interface == NULL || gateway == NULL) {
                        ERR("Invalid parameter");
                        netconfig_error_invalid_parameter(context);
-                       return FALSE;
-               }
-
-               buf = ip_addr;
-               ch = strchr(buf, '/');
-               pos = ch - buf + 1;
-               if (ch) {
-                       prefix_len = atoi(ch + 1);
-                       ip_addr[pos-1] = '\0';
-               } else {
-                       prefix_len = 128;
+                       return TRUE;
                }
 
-               if (netconfig_add_route_ipv6(ip_addr, interface, gateway, prefix_len) < 0) {
+               if (netconfig_add_route_ipv6(interface, gateway) < 0) {
                        DBG("Failed to add a new route");
                        netconfig_error_permission_denied(context);
-                       return FALSE;
+                       return TRUE;
                }
                break;
        default:
                DBG("Unknown Address Family");
                netconfig_error_invalid_parameter(context);
-               return FALSE;
+               return TRUE;
        }
 
        DBG("Successfully added a new route");
@@ -1363,10 +1356,6 @@ static gboolean handle_remove_route(
        gchar *const args[] = { "/sbin/route", "del", "-net", ip_addr, gw_str,
                "netmask", netmask, "dev", interface, NULL };
        char *const envs[] = { NULL };
-       const char* buf = NULL;
-       char* ch = NULL;
-       int prefix_len = 0;
-       int pos = 0;
 
        DBG("ip_addr(%s), netmask(%s), interface(%s), gateway(%s)", ip_addr, netmask, interface, gateway);
 
@@ -1375,41 +1364,31 @@ static gboolean handle_remove_route(
                if (ip_addr == NULL || netmask == NULL || interface == NULL) {
                        DBG("Invalid parameter!");
                        netconfig_error_invalid_parameter(context);
-                       return FALSE;
+                       return TRUE;
                }
                if (netconfig_execute_file(path, args, envs) < 0) {
                        DBG("Failed to remove the route");
                        netconfig_error_permission_denied(context);
-                       return FALSE;
+                       return TRUE;
                }
                break;
        case AF_INET6:
                if (ip_addr == NULL || interface == NULL || gateway == NULL) {
                        DBG("Invalid parameter!");
                        netconfig_error_invalid_parameter(context);
-                       return FALSE;
+                       return TRUE;
                }
 
-               buf = ip_addr;
-               ch = strchr(buf, '/');
-               pos = ch - buf + 1;
-               if (ch) {
-                       prefix_len = atoi(ch + 1);
-                       ip_addr[pos-1] = '\0';
-               } else {
-                       prefix_len = 128;
-               }
-
-               if (netconfig_del_route_ipv6(ip_addr, interface, gateway, prefix_len) < 0) {
+               if (netconfig_del_route_ipv6(interface, gateway) < 0) {
                        DBG("Failed to remove the route");
                        netconfig_error_permission_denied(context);
-                       return FALSE;
+                       return TRUE;
                }
                break;
        default:
                DBG("Unknown Address Family");
                netconfig_error_invalid_parameter(context);
-               return FALSE;
+               return TRUE;
        }
 
        DBG("Successfully removed the route");
@@ -1449,7 +1428,7 @@ gboolean handle_ethernet_cable_state(Network *object,
        if (ret != 0) {
                DBG("Failed to get ethernet cable state");
                netconfig_error_fail_ethernet_cable_state(context);
-               return FALSE;
+               return TRUE;
        }
 
        DBG("Successfully get ethernet cable state[%d]", state);
@@ -1478,7 +1457,7 @@ gboolean handle_preferred_ipv6_address(Network *object,
        if (address == NULL) {
                DBG("Failed to get preferred IPv6 address");
                netconfig_error_fail_preferred_ipv6_address(context);
-               return FALSE;
+               return TRUE;
        }
 
        DBG("Successfully get preferred IPv6 address[%s]", address);