Fixed memory related issues reported by valgrind.
[platform/core/connectivity/net-config.git] / src / wifi-bssid-scan.c
index f285c52..200a671 100755 (executable)
@@ -325,14 +325,39 @@ void netconfig_wifi_bssid_signal_scanaborted(void)
        __netconfig_set_bssid_scan_mode(FALSE);
 }
 
+static void __netconfig_wifi_bssid_scan_request_reply(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+{
+       GVariant *message;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+
+       conn = G_DBUS_CONNECTION(source_object);
+       message = g_dbus_connection_call_finish(conn, res, &error);
+
+       if (message == NULL) {
+               if (error != NULL) {
+                       ERR("Fail to request status [%d: %s]", error->code, error->message);
+                       g_error_free(error);
+               } else {
+                       ERR("Fail to request bssid scan");
+               }
+       } else {
+               DBG("Successfully requested bssid scan");
+               g_variant_unref(message);
+       }
+
+       netconfig_gdbus_pending_call_unref();
+}
+
 static int __netconfig_wifi_bssid_request_scan(char *if_path)
 {
-       GDBusConnection *connection = NULL;
        GVariant *message = NULL;
        GVariantBuilder *builder = NULL;
        const char *key1 = "Type";
        const char *val1 = "passive";
        gboolean is_free_required = FALSE;
+       gboolean reply = FALSE;
 
        if (if_path == NULL) {
                if_path = netconfig_wifi_get_supplicant_interface();
@@ -341,13 +366,7 @@ static int __netconfig_wifi_bssid_request_scan(char *if_path)
 
        if (if_path == NULL) {
                DBG("Fail to get wpa_supplicant DBus path");
-               return -ESRCH;
-       }
-
-       connection = netdbus_get_connection();
-       if (connection == NULL) {
-               ERR("Failed to get GDBusconnection");
-               return -EIO;
+               goto out;
        }
 
        builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
@@ -355,24 +374,26 @@ static int __netconfig_wifi_bssid_request_scan(char *if_path)
        message = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
        g_variant_builder_unref(builder);
 
-       g_dbus_connection_call(connection,
+       DBG("[net-config]: TizenMW-->WPAS: .Interface.Scan");
+       reply = netconfig_supplicant_invoke_dbus_method_nonblock(
                        SUPPLICANT_SERVICE,
                        if_path,
                        SUPPLICANT_INTERFACE ".Interface",
                        "Scan",
                        message,
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       NETCONFIG_DBUS_REPLY_TIMEOUT,
-                       netdbus_get_cancellable(),
-                       NULL,
-                       NULL);
+                       (GAsyncReadyCallback) __netconfig_wifi_bssid_scan_request_reply);
+
+       if (reply != TRUE) {
+               ERR("Fail to Scan");
+               goto out;
+       }
 
        netconfig_is_device_scanning = TRUE;
 
+out:
        if (is_free_required)
                g_free(if_path);
-       g_variant_unref(message);
+
        /* Clear bss_info_list for the next scan result */
        if (bssid_info_list) {
                g_slist_free_full(bssid_info_list, g_free);
@@ -387,7 +408,7 @@ static int __netconfig_wifi_bssid_request_scan(char *if_path)
 static void __netconfig_wifi_interface_create_result(
                GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
-       GVariant *message;
+       GVariant *message = NULL;
        gchar *path = NULL;
        GDBusConnection *conn = NULL;
        GError *error = NULL;
@@ -410,48 +431,43 @@ static void __netconfig_wifi_interface_create_result(
                        g_free(path);
                } else
                        __netconfig_wifi_bssid_request_scan(NULL);
+
+               g_error_free(error);
        } else {
                ERR("Failed to create interface, Error: %d[%s]", error->code, error->message);
                __netconfig_set_bssid_scan_mode(FALSE);
                wifi_power_driver_and_supplicant(FALSE);
+               g_error_free(error);
        }
 
        g_variant_unref(message);
+       netconfig_gdbus_pending_call_unref();
 }
 
 static int  __netconfig_wifi_bssid_create_interface(void)
 {
-       GDBusConnection *connection = NULL;
        GVariant *message = NULL;
        GVariantBuilder *builder = NULL;
        const char *key = "Ifname";
        const char *val = WIFI_IFNAME;
-
-       connection = netdbus_get_connection();
-       if (connection == NULL) {
-               DBG("Failed to get GDBusconnection");
-               return -EIO;
-       }
+       gboolean reply = FALSE;
 
        builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        g_variant_builder_add(builder, "{sv}", key, g_variant_new_string(val));
        message = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
        g_variant_builder_unref(builder);
 
-       g_dbus_connection_call(connection,
+       DBG("[net-config]: TizenMW-->WPAS: CreateInterface");
+       reply = netconfig_supplicant_invoke_dbus_method_nonblock(
                        SUPPLICANT_SERVICE,
                        SUPPLICANT_PATH,
                        SUPPLICANT_INTERFACE,
                        "CreateInterface",
                        message,
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       NETCONFIG_DBUS_REPLY_TIMEOUT,
-                       netdbus_get_cancellable(),
-                       (GAsyncReadyCallback) __netconfig_wifi_interface_create_result,
-                       NULL);
+                       (GAsyncReadyCallback) __netconfig_wifi_interface_create_result);
 
-       g_variant_unref(message);
+       if (reply != TRUE)
+               ERR("Fail to CreateInterface");
 
        return 0;
 }