Don't free dbus method invocation twice
[platform/core/connectivity/net-config.git] / src / wifi-agent.c
index b2dd9d7..bff2fb0 100755 (executable)
@@ -231,38 +231,38 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent,
                }
        }
 
+       g_variant_iter_free(iter);
+
        if (updated == TRUE) {
                reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
                                service, CONNMAN_SERVICE_INTERFACE, "Connect",
                                NULL, __netconfig_wifi_connect_reply);
-               if (reply == TRUE) {
-                       g_dbus_method_invocation_return_value(context, NULL);
-               } else {
+               if (reply != TRUE) {
+                       ERR("Fail to connect Wi-Fi");
+                       __netconfig_agent_clear_fields();
                        error = g_error_new(G_DBUS_ERROR,
                                        G_DBUS_ERROR_AUTH_FAILED,
                                        CONNMAN_ERROR_INTERFACE ".InvalidArguments");
 
                        g_dbus_method_invocation_return_gerror(context, error);
                        g_clear_error(&error);
+                       return TRUE;
                }
        } else {
+               ERR("Fail to connect Wi-Fi");
+               __netconfig_agent_clear_fields();
+
                error = g_error_new(G_DBUS_ERROR,
                                G_DBUS_ERROR_AUTH_FAILED,
                                CONNMAN_ERROR_INTERFACE ".InvalidArguments");
 
                g_dbus_method_invocation_return_gerror(context, error);
                g_clear_error(&error);
+               return TRUE;
        }
 
-       if (reply != TRUE) {
-               ERR("Fail to connect Wi-Fi");
-
-               __netconfig_agent_clear_fields();
-       }
-       g_variant_iter_free(iter);
-
        net_connman_agent_complete_set_field(connman_agent, context);
-       return reply;
+       return TRUE;
 }
 
 gboolean handle_request_input(NetConnmanAgent *connman_agent,