From: DoHyun Pyun Date: Wed, 30 Oct 2019 06:43:35 +0000 (+0900) Subject: Release resources for the notify file destriptor properly X-Git-Tag: accepted/tizen/unified/20191101.042113^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f1af9cb1dfc0c773e09a84ec6093a6358d2a229;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git Release resources for the notify file destriptor properly If we close the fd only, io channel and watcher resource is not released. So it occurs critical problems with next logs. ecore<4672> ../src/lib/ecore/ecore_main.c:2083 _ecore_main_fd_handlers_bads_rem() Removing bad fds ecore<4672> ../src/lib/ecore/ecore_main.c:2130 _ecore_main_fd_handlers_bads_rem() No bad fd found. Maybe a foreign fd from glib? Change-Id: I683aa747018ff6139d31b48207b568da4dab8cae Signed-off-by: DoHyun Pyun --- diff --git a/bt-api/bt-gatt-client.c b/bt-api/bt-gatt-client.c index 1b4cada..d400804 100755 --- a/bt-api/bt-gatt-client.c +++ b/bt-api/bt-gatt-client.c @@ -2262,11 +2262,15 @@ static bt_gatt_characteristic_notify_info_t * bluetooth_gatt_client_create_watc memcpy(chr_info->UUID, uuid, 16); channel = g_io_channel_unix_new(fd); + + chr_info->io_channel = channel; + g_io_channel_set_encoding(channel, NULL, NULL); g_io_channel_set_buffered(channel, FALSE); - g_io_channel_set_close_on_unref(channel, FALSE); + g_io_channel_set_close_on_unref(channel, TRUE); g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL); - g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP), + + chr_info->watch_id = g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP), bluetooth_gatt_client_notify_channel_watch_cb, chr_info); return chr_info; @@ -2296,7 +2300,18 @@ BT_EXPORT_API int bluetooth_gatt_client_watch_characteristics( if (chr_info && !is_notify) { BT_INFO("Already CCCD enabled. fd %d", chr_info->notify_fd); - close(chr_info->notify_fd); + if (chr_info->watch_id > 0) + g_source_remove(chr_info->watch_id); + + if (chr_info->io_channel) { + g_io_channel_shutdown(chr_info->io_channel, TRUE, NULL); + g_io_channel_unref(chr_info->io_channel); + } + + gatt_characteristic_notify_list = g_slist_remove(gatt_characteristic_notify_list, chr_info); + + g_free(chr_info); + return result; } #endif diff --git a/bt-api/include/bt-gatt-client.h b/bt-api/include/bt-gatt-client.h index 4ecc07c..8749ee9 100644 --- a/bt-api/include/bt-gatt-client.h +++ b/bt-api/include/bt-gatt-client.h @@ -55,6 +55,8 @@ typedef struct { int mtu; unsigned char UUID[16]; char address[BLUETOOTH_ADDRESS_STRING_LENGTH]; + void *io_channel; + guint watch_id; } bt_gatt_characteristic_notify_info_t;