From 19dc5fd3534313eb060f240d6318ab09ad40a03f Mon Sep 17 00:00:00 2001 From: Milind Ramesh Murhekar Date: Thu, 20 Jul 2017 16:44:16 +0530 Subject: [PATCH] Remove dead code and Fix memory leak Decription: g_free(ifname) will not be executed as ifname pointer will always be NULL before memory assignment. Change-Id: Id4e05e6ec2790b97c595cb14547f3d3ec44ec351 Signed-off-by: Milind Ramesh Murhekar --- src/network-state.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/network-state.c b/src/network-state.c index 00c8cc2..0afa303 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -819,24 +819,30 @@ void netconfig_update_default_profile(const char *profile) /* default profile is NULL and new connected profile is NULL */ if (!profile) { - profile = __netconfig_get_default_profile(); + char *tmp_profile = __netconfig_get_default_profile(); - if (profile && netconfig_is_cellular_profile(profile) && - !netconfig_is_cellular_internet_profile(profile)) { + if (tmp_profile && netconfig_is_cellular_profile(tmp_profile) && + !netconfig_is_cellular_internet_profile(tmp_profile)) { DBG("not a default cellular profile"); - profile = NULL; + g_free(tmp_profile); + tmp_profile = NULL; } - if (!profile) { + if (!tmp_profile) { __netconfig_update_default_connection_info(); return; } + + netconfig_default_connection_info.profile = g_strdup(tmp_profile); + __netconfig_get_default_connection_info(tmp_profile); + __netconfig_update_default_connection_info(); + g_free(tmp_profile); + return; } netconfig_default_connection_info.profile = g_strdup(profile); __netconfig_get_default_connection_info(profile); __netconfig_update_default_connection_info(); - } void netconfig_update_default(void) @@ -890,9 +896,10 @@ 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); - if (ifname) - g_free(ifname); ifname = g_strdup(value); + g_free(key1); + g_variant_unref(variant); + break; } } } -- 2.7.4