Apply tizen 3.0 based product patchsets
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-gatt-service.c
index 77bee58..7cb8ee8 100644 (file)
@@ -1624,6 +1624,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
                                        NULL, /* GDBusAuthObserver */
                                        NULL,
                                        &err);
+               g_free(address);
                if (!g_conn) {
                        if (err) {
                                BT_ERR("Unable to connect to dbus: %s", err->message);
@@ -1647,7 +1648,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
                                        NULL, /* GDBusAuthObserver */
                                        NULL,
                                        &err);
-
+               g_free(address);
                if (!local_system_gconn) {
                        BT_ERR("Unable to connect to dbus: %s", err->message);
                        g_clear_error(&err);
@@ -1691,7 +1692,6 @@ BT_EXPORT_API int bluetooth_gatt_init(void)
        /* Register ObjectManager interface */
        node_info = __bt_gatt_create_method_node_info(
                                        manager_introspection_xml);
-
        if (node_info == NULL) {
                BT_ERR("failed to get node info");
                goto failed;
@@ -1705,7 +1705,7 @@ BT_EXPORT_API int bluetooth_gatt_init(void)
                                                        &manager_interface_vtable,
                                                        NULL, NULL, &error);
        }
-
+       g_dbus_node_info_unref(node_info);
        if (manager_id == 0) {
                BT_ERR("failed to register: %s", error->message);
                g_error_free(error);
@@ -1786,7 +1786,6 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
 
        node_info = __bt_gatt_create_method_node_info(
                                        service_introspection_xml);
-
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1797,6 +1796,7 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
                                        node_info->interfaces[0],
                                        &serv_interface_vtable,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -1890,7 +1890,6 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
 
        node_info = __bt_gatt_create_method_node_info(
                                        characteristics_introspection_xml);
-
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1901,6 +1900,7 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
                                        node_info->interfaces[0],
                                        &char_interface_vtable,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -2091,7 +2091,6 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
 
        node_info = __bt_gatt_create_method_node_info(
                                        descriptor_introspection_xml);
-
        if (node_info == NULL) {
                g_strfreev(line_argv);
                g_free(serv_path);
@@ -2105,6 +2104,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
                                node_info->interfaces[0],
                                &desc_interface_vtable,
                                NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -2166,6 +2166,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        g_strfreev(line_argv);
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder2);
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -2369,6 +2370,7 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
        int i = 0;
        gchar **line_argv = NULL;
        gchar *serv_path = NULL;
+       const char *value = NULL;
 
        line_argv = g_strsplit_set(char_path, "/", 0);
        serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
@@ -2427,7 +2429,18 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
 
                char_info->value_length = value_length;
 
-               char_info->char_value = (char *)realloc(char_info->char_value, value_length);
+               value = (char *)realloc(char_info->char_value, value_length);
+               if (value == NULL) {
+                       g_free(serv_path);
+                       g_strfreev(line_argv);
+                       g_variant_builder_unref(inner_builder);
+                       g_variant_builder_unref(outer_builder);
+                       g_variant_builder_unref(invalidated_builder);
+
+                       return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+               }
+
+               char_info->char_value = (char*)value;
                if (char_info->char_value) {
                        for (i = 0; i < value_length; i++)
                                char_info->char_value[i] = char_value[i];
@@ -2600,33 +2613,10 @@ BT_EXPORT_API int bluetooth_gatt_send_response(int request_id, guint req_type,
 
        if (resp_state != BLUETOOTH_ATT_ERROR_NONE) {
                BT_ERR("resp_state is 0x%X", resp_state);
-
-               switch (resp_state) {
-               case BLUETOOTH_ATT_ERROR_WRITE_REQUEST_REJECTED:
-                       g_dbus_method_invocation_return_dbus_error(req_info->context,
-                       "org.bluez.Error.Failed", "Write Request Rejected");
-                       break;
-               case BLUETOOTH_ATT_ERROR_OBJECT_NOT_SELECTED:
-                       g_dbus_method_invocation_return_dbus_error(req_info->context,
-                       "org.bluez.Error.Failed", "Object Not Selected");
-                       break;
-               case BLUETOOTH_ATT_ERROR_CONCURRENCY_LIMIT_EXCEEDED:
-                       g_dbus_method_invocation_return_dbus_error(req_info->context,
-                       "org.bluez.Error.Failed", "Concurrency Limit Exceeded");
-                       break;
-               case BLUETOOTH_ATT_ERROR_OBJECT_NAME_EXISTS:
-                       g_dbus_method_invocation_return_dbus_error(req_info->context,
-                       "org.bluez.Error.Failed", "Object Name Already Exists");
-                       break;
-               case BLUETOOTH_ATT_ERROR_CCCD_IMPROPERLY_CONFIGURED:
-                       g_dbus_method_invocation_return_dbus_error(req_info->context,
-                       "org.bluez.Error.Failed", "CCC Improperly Configured");
-                       break;
-               default:
-                       g_dbus_method_invocation_return_dbus_error(req_info->context,
-                       "org.bluez.Error.Failed", "Application Error");
-                       break;
-               }
+               char err_msg[20] = { 0, };
+               g_snprintf(err_msg, sizeof(err_msg), "ATT error: 0x%02x", resp_state);
+               g_dbus_method_invocation_return_dbus_error(req_info->context,
+                                               "org.bluez.Error.Failed", err_msg);
 
                gatt_requests = g_slist_remove(gatt_requests, req_info);