Fixed various issues reported by valgrind 74/181274/1 accepted/tizen/unified/20180612.044205 submit/tizen/20180612.012523
authorSaurav Babu <saurav.babu@samsung.com>
Mon, 11 Jun 2018 11:10:54 +0000 (16:40 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Mon, 11 Jun 2018 11:10:54 +0000 (16:40 +0530)
==13792== Invalid read of size 4
==13792==    at 0x4D4AEE4: g_type_check_instance_is_fundamentally_a (in /usr/lib/libgobject-2.0.so.0.5200.2)
==13792==  Address 0x4ebdc48 is 0 bytes inside a block of size 136 free'd
==13792==    at 0x4846EC8: free (vg_replace_malloc.c:530)
==13792==    by 0x4D49A5B: g_type_free_instance (in /usr/lib/libgobject-2.0.so.0.5200.2)
==13792==    by 0x4885443: _net_dbus_close_gdbus_call (network_internal.c:640)
==13792==    by 0x4882BA5: net_deregister_client_ext (network_interface.c:2837)
==13792==    by 0x48900CD: _wifi_deinit (wifi_internal.c:1447)
==13792==    by 0x4897F55: wifi_manager_deinitialize (wifi_manager.c:236)
==13792==    by 0x10D997: ??? (in /usr/bin/wifi_manager_test)
==13792==    by 0x110087: ??? (in /usr/bin/wifi_manager_test)
==13792==    by 0x48FF8E7: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x48FFC77: ??? (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x48FFFD7: g_main_loop_run (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x10B30B: ??? (in /usr/bin/wifi_manager_test)
==13792==  Block was alloc'd at
==13792==    at 0x48458A4: malloc (vg_replace_malloc.c:299)
==13792==    by 0x49051B3: g_malloc (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x491E4A3: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x491EA7F: g_slice_alloc0 (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x4D4979B: g_type_create_instance (in /usr/lib/libgobject-2.0.so.0.5200.2)
==13792==    by 0x4D29853: ??? (in /usr/lib/libgobject-2.0.so.0.5200.2)
==13792==    by 0x4D2BBF7: g_object_new_valist (in /usr/lib/libgobject-2.0.so.0.5200.2)

==13792== 1,150 bytes in 138 blocks are definitely lost in loss record 956 of 970
==13792==    at 0x48458A4: malloc (vg_replace_malloc.c:299)
==13792==    by 0x49051B3: g_malloc (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x491FF03: g_strdup (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x493CF0B: ??? (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x493CB5F: ??? (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x493DF1B: g_variant_iter_next (in /usr/lib/libglib-2.0.so.0.5200.2)
==13792==    by 0x487E4C7: __net_extract_wifi_info (network_interface.c:1070)
==13792==    by 0x487FAFD: __net_extract_all_services (network_interface.c:1184)
==13792==    by 0x487FAFD: __net_extract_services (network_interface.c:1218)
==13792==    by 0x487FAFD: _net_get_profile_list (network_interface.c:1383)
==13792==    by 0x4883AAF: net_get_profile_list (network_interface.c:3134)
==13792==    by 0x488F83F: __update_profile_iterator (wifi_internal.c:320)
==13792==    by 0x4892A59: _wifi_foreach_found_ap (wifi_internal.c:2239)
==13792==    by 0x10DD11: ??? (in /usr/bin/wifi_manager_test)

==13655== 96,381 (8 direct, 96,373 indirect) bytes in 1 blocks are definitely lost in loss record 1,157 of 1,158
==13655==    at 0x48458A4: malloc (vg_replace_malloc.c:299)
==13655==    by 0x49051B3: g_malloc (in /usr/lib/libglib-2.0.so.0.5200.2)
==13655==    by 0x491E4A3: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.5200.2)
==13655==    by 0x491FA13: g_slist_append (in /usr/lib/libglib-2.0.so.0.5200.2)
==13655==    by 0x487FB0D: __net_extract_all_services (network_interface.c:1191)
==13655==    by 0x487FB0D: __net_extract_services (network_interface.c:1218)
==13655==    by 0x487FB0D: _net_get_profile_list (network_interface.c:1383)
==13655==    by 0x487A239: _net_dbus_connect_service (network_dbus.c:1272)
==13655==    by 0x4884D05: _net_open_connection_with_wifi_info (network_internal.c:330)
==13655==    by 0x48810E9: net_open_connection_with_wifi_info (network_interface.c:2037)
==13655==    by 0x488F8E9: __connect_with_wifi_info (wifi_internal.c:521)
==13655==    by 0x4892D3D: _wifi_open_profile (wifi_internal.c:2354)
==13655==    by 0x10B963: ??? (in /usr/bin/wifi_manager_test)
==13655==    by 0x4892A91: _wifi_foreach_found_ap (wifi_internal.c:2255)

Change-Id: I417fcd081ff51509735e2e87dc2b96e53812f34b
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
include/network_interface.h
include/wifi_internal.h
src/network_dbus.c
src/network_interface.c
src/network_internal.c
src/wifi_internal.c

index 8acf82e955dfe954f1bff138d463772b743ac7fa..5a5e3432898874df4e399369e3050cb72c14c647 100755 (executable)
@@ -148,9 +148,9 @@ typedef enum {
 } net_vsie_frames_e;
 
 typedef struct {
-        char bssid[18];
-        int strength;
-        int frequency;
+       char bssid[18];
+       int strength;
+       int frequency;
 } net_profile_bssid_list_s;
 
 typedef struct {
index 75d2767d1ce6e1798680e4f119b90c1d6521bfc2..5c30a49f37446325611b12ee6598edf8e4bddaee 100755 (executable)
@@ -340,6 +340,7 @@ int _wifi_get_ip_conflict_state(wifi_manager_ip_conflict_state_e *state);
 int _wifi_get_ip_conflict_period(unsigned int* initial_time);
 int _wifi_get_wps_generated_pin(char **wps_pin);
 
+void __clear_profile_list(GSList **iterator);
 
 /* WIFI Privilege Check */
 int _wifi_check_get_privilege();
index 5ebfb8f18a22f13306d14fe5c72e086f5354bcd1..89029dea2c4fb6f3c959e7ec421b3be5424c352f 100755 (executable)
@@ -1360,7 +1360,8 @@ error:
                                0, sizeof(network_request_table_s));
        }
 
-       NET_MEMFREE(prof_info);
+       __clear_profile_list(&profile_list);
+
        g_free(grp_name);
 
        __NETWORK_FUNC_EXIT__;
index 34e25635c22c0d3009b28da77f2ec8c124a5f567..94cb70e518cae7f78966017c05563660125e0406 100755 (executable)
@@ -1065,14 +1065,17 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof
                } else if (g_strcmp0(key, "BSSID.List") == 0) {
                        GVariantIter *iter_sub = NULL;
                        net_profile_bssid_list_s *bssid_list = NULL;
+                       gchar *bssid_key = NULL;
+                       GVariant *bssid_var = NULL;
                        g_variant_get(var, "a{sv}", &iter_sub);
 
-                       while (g_variant_iter_next(iter_sub, "{sv}", &value, &var)) {
-                               if (g_strcmp0(value, "BSSID") == 0) {
+                       while (g_variant_iter_loop(iter_sub, "{sv}", &bssid_key,
+                                                                          &bssid_var)) {
+                               if (g_strcmp0(bssid_key, "BSSID") == 0) {
                                        bssid_list = (net_profile_bssid_list_s *)g_try_malloc0(sizeof(net_profile_bssid_list_s));
 
                                        if (bssid_list) {
-                                               value = g_variant_get_string(var, NULL);
+                                               value = g_variant_get_string(bssid_var, NULL);
 
                                                if (value != NULL)
                                                        g_strlcpy(bssid_list->bssid, value, 18);
@@ -1080,13 +1083,16 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof
                                                        WIFI_LOG(WIFI_ERROR, "Value is empty");
                                        } else {
                                                WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
+                                               g_variant_unref(bssid_var);
+                                               g_free(bssid_key);
                                                break;
                                        }
-                               } else if (bssid_list && g_strcmp0(value, "Strength") == 0) {
-                                       bssid_list->strength = (int)g_variant_get_uint16(var);
-                               } else if (bssid_list && g_strcmp0(value, "Frequency") == 0) {
-                                       bssid_list->frequency = (int)g_variant_get_uint16(var);
-                                       ProfInfo->bssid_list = g_slist_append(ProfInfo->bssid_list, bssid_list);
+                               } else if (bssid_list && g_strcmp0(bssid_key, "Strength") == 0) {
+                                       bssid_list->strength = (int)g_variant_get_uint16(bssid_var);
+                               } else if (bssid_list && g_strcmp0(bssid_key, "Frequency") == 0) {
+                                       bssid_list->frequency = (int)g_variant_get_uint16(bssid_var);
+                                       ProfInfo->bssid_list = g_slist_append(ProfInfo->bssid_list,
+                                                                                                                 bssid_list);
                                }
                        }
                        g_variant_iter_free(iter_sub);
@@ -1244,6 +1250,7 @@ static int __net_get_profile_info(
                goto done;
        }
 
+       Error = NET_ERR_NO_PROFILE;
        g_variant_get(message, "(a(oa{sv}))", &iter);
        while (g_variant_iter_loop(iter, "(oa{sv})", &path, &service)) {
                if (g_strcmp0(ProfileName, path) == 0) {
index 85d6daf8b882d09432e4a469b5bc83c60791eba4..6a24aa466af08188f136e1f0eeda5fff48b77e95 100755 (executable)
@@ -635,9 +635,9 @@ int _net_dbus_close_gdbus_call(void)
                        WIFI_LOG(WIFI_ERROR, "A handle of libnetwork is not NULL");
 
                gdbus_conn.handle_libnetwork = dlopen("/usr/lib/libnetwork.so", RTLD_LAZY);
+               g_object_unref(gdbus_conn.connection);
        }
 
-       g_object_unref(gdbus_conn.connection);
        if (G_IS_OBJECT(gdbus_conn.connection))
                g_clear_object(&gdbus_conn.connection);
        else
index 85c0e94c41e9311079ff37f145659926b497b990..4afd0b124808e827610cb3b8c8da4822e5e8c417 100755 (executable)
@@ -301,7 +301,7 @@ static void __clear_profile_internal_list(GSList **iterator)
 
 //LCOV_EXCL_STOP
 
-static void __clear_profile_list(GSList **iterator)
+void __clear_profile_list(GSList **iterator)
 {
        if (*iterator) {
                *iterator = g_slist_nth(*iterator, 0);
@@ -573,7 +573,7 @@ static void __state_changed_cb(char *profile_name,
        GSList *list;
        net_profile_info_s *ap_info = NULL;
 
-       if (profile_name == NULL)
+       if (profile_name == NULL || profile_info == NULL)
                return;
 
        WIFI_LOG(WIFI_INFO, "%s state changed : %s", profile_name, __convert_ap_state_to_string(state));
@@ -1150,10 +1150,21 @@ static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data)
                        break;
                }
 
-               if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE)
+               if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE) {
                        __state_changed_cb(event_cb->ProfileName, &prof_info,
                                                WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
-               else
+
+                       /* Free internal GSList */
+                       if (prof_info.vsie_list) {
+                               g_slist_free_full(prof_info.vsie_list, g_free);
+                               prof_info.vsie_list = NULL;
+                       }
+
+                       if (prof_info.bssid_list) {
+                               g_slist_free_full(prof_info.bssid_list, g_free);
+                               prof_info.bssid_list = NULL;
+                       }
+               } else
                        __state_changed_cb(event_cb->ProfileName, NULL,
                                                WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
 
@@ -1174,10 +1185,21 @@ static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data)
 
                switch (event_cb->Error) {
                case NET_ERR_NONE:
-                       if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE)
+                       if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE) {
                                __state_changed_cb(event_cb->ProfileName, &prof_info,
                                                WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
-                       else
+
+                               /* Free internal GSList */
+                               if (prof_info.vsie_list) {
+                                       g_slist_free_full(prof_info.vsie_list, g_free);
+                                       prof_info.vsie_list = NULL;
+                               }
+
+                               if (prof_info.bssid_list) {
+                                       g_slist_free_full(prof_info.bssid_list, g_free);
+                                       prof_info.bssid_list = NULL;
+                               }
+                       } else
                                __state_changed_cb(event_cb->ProfileName, NULL,
                                                WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED);
 
@@ -1222,9 +1244,20 @@ static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data)
                WIFI_LOG(WIFI_INFO, "state: %s", __convert_ap_state_to_string(ap_state));
                WIFI_LOG(WIFI_INFO, "profile name: %s", event_cb->ProfileName);
 
-               if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE)
+               if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE) {
                        __state_changed_cb(event_cb->ProfileName, &prof_info, ap_state);
-               else if (ap_state == WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED) {
+
+                       /* Free internal GSList */
+                       if (prof_info.vsie_list) {
+                               g_slist_free_full(prof_info.vsie_list, g_free);
+                               prof_info.vsie_list = NULL;
+                       }
+
+                       if (prof_info.bssid_list) {
+                               g_slist_free_full(prof_info.bssid_list, g_free);
+                               prof_info.bssid_list = NULL;
+                       }
+               } else if (ap_state == WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED) {
                        net_profile_info_s *profile = NULL;
                        for (list = profile_iterator; list; list = list->next) {
                                profile = (net_profile_info_s *)list->data;