bt_service: map: Fix proxy leak and double unref
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-map-client.c
index 230490e..3ea576d 100644 (file)
@@ -53,102 +53,10 @@ bt_session_info_t *session_info;
 static void __bt_free_session_info(bt_session_info_t *info)
 {
        ret_if(info == NULL);
-
-       /* TODO: MAP bt_session_info_t, see bt-service-opp-client.c */
-
-       g_free(info->address);
-       g_free(info);
-}
-
-static void __bt_free_session_data(gpointer data)
-{
-       bt_session_data_t *info = data;
-
-       ret_if(info == NULL);
-
-       _bt_delete_request_id(info->request_id);
-
-       /* TODO: MAP bt_session_data_t, see bt-service-opp-client.c */
-
        g_free(info->address);
        g_free(info);
 }
 
-static void __bt_session_release_cb(GDBusProxy *proxy,
-                               GAsyncResult *res, gpointer user_data)
-{
-       BT_DBG("+");
-       ret_if(session_info == NULL);
-
-       GError *error = NULL;
-       int result = BLUETOOTH_ERROR_NONE;
-       GVariant *param = NULL;
-       g_dbus_proxy_call_finish(proxy, res, &error);
-       if (proxy)
-               g_object_unref(proxy);
-
-       if (error) {
-               BT_ERR("%s", error->message);
-               g_error_free(error);
-
-               result = BLUETOOTH_ERROR_INTERNAL;
-       } else {
-               BT_DBG("Session Removed");
-       }
-
-       session_info->result = result;
-       param = g_variant_new("(isi)", session_info->result,
-                               session_info->address,
-                               session_info->request_id);
-       /* Send the event in only error none case */
-       _bt_send_event(BT_OPP_CLIENT_EVENT,
-                       BLUETOOTH_EVENT_OPC_DISCONNECTED,
-                       param);
-
-       __bt_free_session_info(session_info);
-       session_info = NULL;
-
-       _bt_map_client_event_deinit();
-
-       /* Operate remain works */
-       /* TODO: MAP */
-
-       return;
-fail:
-
-       BT_DBG("-");
-
-       return;
-}
-
-static int _bt_remove_session()
-{
-       GDBusConnection *g_conn;
-       GDBusProxy *session_proxy;
-       GError *err = NULL;
-
-       g_conn = _bt_gdbus_get_session_gconn();
-       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-       retv_if(session_info->session_path == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
-
-       session_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
-                                               NULL, BT_OBEXD_DBUS_NAME,
-                                               BT_OBEX_CLIENT_PATH,
-                                               BT_OBEX_CLIENT_INTERFACE,
-                                               NULL, &err);
-
-       retv_if(session_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       g_dbus_proxy_call(session_proxy, "RemoveSession",
-               g_variant_new("(o)", session_info->session_path),
-               G_DBUS_CALL_FLAGS_NONE,
-               DBUS_TIMEOUT, NULL,
-               (GAsyncReadyCallback)__bt_session_release_cb,
-               NULL);
-
-       return BLUETOOTH_ERROR_NONE;
-}
-
 void _bt_map_disconnected(const char *session_path)
 {
        BT_DBG("+");
@@ -174,83 +82,12 @@ void _bt_map_disconnected(const char *session_path)
        BT_DBG("-");
 }
 
-static void __bt_create_session_cb(GDBusProxy *proxy,
-                               GAsyncResult *res, gpointer user_data)
-{
-       BT_DBG("+");
-
-       GError *error = NULL;
-       GVariant *value;
-       int result = BLUETOOTH_ERROR_NONE;
-       char *session_path = NULL;
-       GVariant *param = NULL;
-
-       value = g_dbus_proxy_call_finish(proxy, res, &error);
-       if (value) {
-               g_variant_get(value, "(o)", &session_path);
-               g_variant_unref(value);
-       }
-       if (error) {
-
-               BT_ERR("%s", error->message);
-               g_clear_error(&error);
-
-               result = BLUETOOTH_ERROR_INTERNAL;
-       } else {
-               BT_DBG("Session created");
-               if (session_info != NULL)
-                       session_info->session_path = g_strdup(session_path);
-       }
-       g_free(session_path);
-       g_object_unref(proxy);
-       ret_if(session_info == NULL);
-
-       session_info->result = result;
-       param = g_variant_new("(isi)", result,
-                               session_info->address,
-                               session_info->request_id);
-       /* Send the event in only error none case */
-       _bt_send_event(BT_MAP_CLIENT_EVENT,
-                       BLUETOOTH_EVENT_MAP_CONNECTED,
-                       param);
-
-       if (result != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("Calling __bt_session_release");
-               gboolean ret = __bt_session_release();
-
-               __bt_free_session_info(session_info);
-               session_info = NULL;
-
-               if (ret == FALSE) {
-                       BT_DBG("ReleaseSession Not called");
-                       /* Operate remain works */
-
-                       /* TODO: MAP */
-
-               }
-       } else {
-
-               /* TODO: MAP */
-
-       }
-       BT_DBG("-");
-
-}
-
-static int __bt_opp_client_start_XXXXXXXXXX(int request_id, char *address
-                                       /* parameters................... */)
-{
-       /* TODO: MAP */
-       return BLUETOOTH_ERROR_NONE;
-}
-
 int _bt_create_session_sync(const char* address, char** session_id)
 {
        BT_DBG("Entered SERVICE create session");
        GDBusConnection *g_conn;
        GDBusProxy *session_proxy;
        GError *err = NULL;
-       const char *session_path;
 
        retv_if(address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
@@ -276,10 +113,11 @@ int _bt_create_session_sync(const char* address, char** session_id)
        g_variant_builder_unref(builder);
        GVariant *param = g_variant_new("(s@a{sv})", address, args);
 
-       char* string = g_variant_print (param, true);
-
        GVariant *value = g_dbus_proxy_call_sync(session_proxy, "CreateSession", param,
                        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+
+       g_object_unref(session_proxy);
+
        if (err != NULL) {
                BT_ERR("Could not create session: %s\n", err->message);
                g_error_free(err);
@@ -325,8 +163,11 @@ int _bt_destroy_session_sync(const char* session_id)
 
        GVariant *param = g_variant_new("(o)", session_id);
 
-       GVariant *value = g_dbus_proxy_call_sync(session_proxy, "RemoveSession", param,
+       g_dbus_proxy_call_sync(session_proxy, "RemoveSession", param,
                        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+
+       g_object_unref(session_proxy);
+
        if (err != NULL) {
                BT_ERR("Could not remove session: %s\n", err->message);
                g_error_free(err);
@@ -350,8 +191,6 @@ int _bt_map_client_set_folder(const char* session_id, const char* name)
        g_conn = _bt_gdbus_get_session_gconn();
        retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       GVariant *param = g_variant_new("(o)", session_id);
-
        message_proxy = g_dbus_proxy_new_sync(g_conn,
                G_DBUS_PROXY_FLAGS_NONE, NULL,
                BT_OBEX_SERVICE_NAME, session_id,
@@ -390,7 +229,6 @@ static void __bt_list_folders_cb(GDBusProxy *proxy,
 
        int result = BLUETOOTH_ERROR_NONE;
        int request_id;
-       int size = 0;
 
        in_param = (GVariant*) user_data;
        g_variant_get(in_param, "(i)", &request_id);
@@ -482,8 +320,6 @@ static void __bt_list_filter_fields_cb(GDBusProxy *proxy,
 
        int result = BLUETOOTH_ERROR_NONE;
        int request_id;
-       char** fields = NULL;
-       int size = 0;
 
        in_param = (GVariant*) user_data;
        g_variant_get(in_param, "(i)", &request_id);
@@ -514,7 +350,6 @@ int _bt_map_client_list_filter_fields(int request_id, GDBusMethodInvocation *con
        GError *err = NULL;
        GDBusConnection *g_conn;
        GDBusProxy *message_proxy;
-       GVariant *ret = NULL;
        int result = BLUETOOTH_ERROR_NONE;
 
        retv_if(session_id == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
@@ -563,7 +398,6 @@ static void __bt_list_messages_cb(
 
        int result = BLUETOOTH_ERROR_NONE;
        int request_id;
-       int size = 0;
 
        in_param = (GVariant*) user_data;
        g_variant_get(in_param, "(i)", &request_id);
@@ -659,8 +493,6 @@ int _bt_map_client_update_inbox(const char* session_id)
        g_conn = _bt_gdbus_get_session_gconn();
        retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       GVariant *param = g_variant_new("(o)", session_id);
-
        message_proxy = g_dbus_proxy_new_sync(g_conn,
                G_DBUS_PROXY_FLAGS_NONE, NULL,
                BT_OBEX_SERVICE_NAME, session_id,
@@ -719,7 +551,7 @@ void _bt_map_on_transfer_finished(const char *transfer_object_path, const int er
                        _bt_send_event(BT_MAP_CLIENT_EVENT, event, param);
 
                        // remove callback data from list
-                       g_slist_remove(transfer_list, transfer);
+                       transfer_list = g_slist_remove(transfer_list, transfer);
 
                        //free memory and break loop
                        free(callback_data->transfer_path);
@@ -737,14 +569,12 @@ static void __bt_push_message_cb(GDBusProxy *proxy,
        BT_DBG("+");
 
        GError *error = NULL;
-       GVariant *value, *in_param, *param;
+       GVariant *value, *in_param;
 
        char *transfer_object_path = NULL;
        GVariantIter *iter = NULL;
 
-       int result = BLUETOOTH_ERROR_NONE;
        int request_id;
-       int size = 0;
 
        in_param = (GVariant*) user_data;
        g_variant_get(in_param, "(i)", &request_id);
@@ -753,13 +583,10 @@ static void __bt_push_message_cb(GDBusProxy *proxy,
        if (error) {
                BT_ERR("%s", error->message);
                g_clear_error(&error);
-               result = BLUETOOTH_ERROR_INTERNAL;
        }
 
-       if (value) {
+       if (value)
                g_variant_get(value, "(oa{sv})", &transfer_object_path, &iter);
-               g_variant_unref(value);
-       }
 
        BT_DBG("transfer object path: [%s]", transfer_object_path);
 
@@ -847,14 +674,12 @@ static void __bt_get_message_cb(GDBusProxy *proxy,
        BT_DBG("+");
 
        GError *error = NULL;
-       GVariant *value, *in_param, *param;
+       GVariant *value, *in_param;
 
        char *transfer_object_path = NULL;
        GVariantIter *iter = NULL;
 
-       int result = BLUETOOTH_ERROR_NONE;
        int request_id;
-       int size = 0;
 
        in_param = (GVariant*) user_data;
        g_variant_get(in_param, "(i)", &request_id);
@@ -863,13 +688,10 @@ static void __bt_get_message_cb(GDBusProxy *proxy,
        if (error) {
                BT_ERR("%s", error->message);
                g_clear_error(&error);
-               result = BLUETOOTH_ERROR_INTERNAL;
        }
 
-       if (value) {
+       if (value)
                g_variant_get(value, "(oa{sv})", &transfer_object_path, &iter);
-               g_variant_unref(value);
-       }
 
        BT_DBG("transfer object path: [%s]", transfer_object_path);