Fix for SVACE (WGID 322531) in setup-adaptor accepted/tizen/unified/20181002.093448 submit/tizen/20181002.025635
authorhwajeong.son <hwajeong.son@samsung.com>
Mon, 1 Oct 2018 10:58:43 +0000 (19:58 +0900)
committerhwajeong.son <hwajeong.son@samsung.com>
Tue, 2 Oct 2018 02:49:24 +0000 (11:49 +0900)
The issue is caused by g_main_loop_new.
If the thread is completed, it should be freed.
In case of error like unitializing case, it should be properly freed.

Change-Id: I1305cfcd24ccd53218818427978fac5242523089

src/setup_network.c

index 6d865d844c7083edd0987f52ba17f257b18aa252..a5a95283f9e9a58d5df75a05591428813cb314d6 100755 (executable)
@@ -308,7 +308,7 @@ static int __wifi_connect_main(sa_wifi_s * info)
        _wifi_data_s wifi_data = { 0, };
 
        int rv = 0;
-       sa_error_e ret = SA_ERROR_UNKNOWN;
+       sa_error_e ret = SA_ERROR_NONE;
        wifi_manager_h wifi_h = NULL;
 
        _D("__wifi_connect_main (ssid=%s, pw=%s)", info->ssid, info->password);
@@ -319,44 +319,67 @@ static int __wifi_connect_main(sa_wifi_s * info)
        }
 
        context = g_main_context_new();
-       g_main_context_push_thread_default(context);    // should be.. to get mainloop message in thread
-       gmain_loop = g_main_loop_new(context, FALSE);
-
-       rv = wifi_manager_initialize(&wifi_h);
-
-       if (rv == WIFI_MANAGER_ERROR_NONE) {
-               // fill the token data
-               wifi_data.ssid = info->ssid;
-               wifi_data.password = info->password;
-               wifi_data.loop = gmain_loop;
-               wifi_data.wifi_h = wifi_h;
-
-               rv = wifi_manager_set_device_state_changed_cb(wifi_h, __wifi_state_changed_cb, (void *)&wifi_data);
-               rv = wifi_manager_activate(wifi_h, __wifi_activate_cb, NULL);
-               if (rv == WIFI_MANAGER_ERROR_ALREADY_EXISTS) {
-                       _D("wifi_manager_active alreay exists");
-                       wifi_manager_scan(wifi_h, __wifi_scan_finished_cb, (void *)&wifi_data);
-               } else if (rv != WIFI_MANAGER_ERROR_NONE) {
-                       _E("wifi_manager_activated failed.[%s]", __print_wifi_error(rv));
-                       return SA_ERROR_UNKNOWN;
-               }
-       } else {
-               _E("Wifi init failed [%s]", __print_wifi_error(rv));
-               return SA_ERROR_UNKNOWN;
-       }
 
-       g_main_loop_run(gmain_loop);
+       if (context != NULL) {
+               g_main_context_push_thread_default(context);    // should be.. to get mainloop message in thread
+               gmain_loop = g_main_loop_new(context, FALSE);
 
-       gmain_loop = NULL;
+               if (gmain_loop != NULL) {
+                       rv = wifi_manager_initialize(&wifi_h);
 
-       wifi_manager_unset_scan_state_changed_cb(wifi_h);
-       wifi_manager_unset_connection_state_changed_cb(wifi_h);
+                       if (rv == WIFI_MANAGER_ERROR_NONE) {
+                               // fill the token data
+                               wifi_data.ssid = info->ssid;
+                               wifi_data.password = info->password;
+                               wifi_data.loop = gmain_loop;
+                               wifi_data.wifi_h = wifi_h;
+
+                               rv = wifi_manager_set_device_state_changed_cb(wifi_h, __wifi_state_changed_cb, (void *)&wifi_data);
+                               if (rv == WIFI_MANAGER_ERROR_NONE) {
+                                       rv = wifi_manager_activate(wifi_h, __wifi_activate_cb, NULL);
+                                       if (rv == WIFI_MANAGER_ERROR_ALREADY_EXISTS) {
+                                               _D("wifi_manager_active alreay exists");
+                                               wifi_manager_scan(wifi_h, __wifi_scan_finished_cb, (void *)&wifi_data);
+                                       } else if (rv != WIFI_MANAGER_ERROR_NONE) {
+                                               _E("wifi_manager_activated failed.[%s]", __print_wifi_error(rv));
+                                               ret = SA_ERROR_UNKNOWN;
+                                       }
+                               } else {
+                                       ret = SA_ERROR_UNKNOWN;
+                                       _E("wifi_manager_set_device_state_changed_cb error");
+                               }
+                       } else {
+                               ret = SA_ERROR_UNKNOWN;
+                               _E("Wifi init failed [%s]", __print_wifi_error(rv));
+                       }
 
-       rv = wifi_manager_deinitialize(wifi_h);
+                       if (ret == SA_ERROR_NONE)
+                               g_main_loop_run(gmain_loop);
 
-       if (rv != WIFI_MANAGER_ERROR_NONE) {
-               _D("Fail to deinitialize.");
-               ret = SA_ERROR_UNKNOWN;
+                       g_main_loop_unref(gmain_loop);
+                       g_main_context_unref(context);
+
+                       if (wifi_h != NULL) {
+                               wifi_manager_unset_scan_state_changed_cb(wifi_h);
+                               wifi_manager_unset_connection_state_changed_cb(wifi_h);
+                       }
+
+                       gmain_loop = NULL;
+                       context = NULL;
+
+                       if (wifi_h != NULL) {
+                       rv = wifi_manager_deinitialize(wifi_h);
+                               if (rv != WIFI_MANAGER_ERROR_NONE) {
+                                       _D("Fail to deinitialize.");
+                                       ret = SA_ERROR_UNKNOWN;
+                               }
+                       }
+               } else {
+                       g_main_context_unref(context);
+                       _E("Fail to create g_main_loop");
+               }
+       } else {
+               _E("Fail to create g_main_context");
        }
 
        _D("__wifi_connect_main completed.");
@@ -684,6 +707,7 @@ static sa_error_e __network_connect(sa_network_s * info)
        if (info->wifi != NULL) {
                if ((info->wifi->enabled == TRUE) && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_WIFI)) {
                        retWifi = __wifi_connect_main(info->wifi);
+
                        _D("return wifi [%d]", retWifi);
                } else {
                        _D("wifi enabled flag is false");