From 09c49fcdac64c9b1674b5dafc8553702c673eeb5 Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Wed, 13 Sep 2023 14:17:29 +0900 Subject: [PATCH] Fix pipe fd management error Change-Id: Ida7802e0a8dd9889612b95dae2b00056c80e8987 Signed-off-by: Junkyeong Kim --- src/cbhm.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/cbhm.c b/src/cbhm.c index 59f693a..8bae588 100644 --- a/src/cbhm.c +++ b/src/cbhm.c @@ -72,7 +72,6 @@ typedef struct { Cbhm_Received_Data *received_data; Cbhm_Data_Offer *cbhm_data_offer; bool data_receive; - int pipe[2]; } Cbhm_Glib_Info; static void @@ -394,9 +393,9 @@ _cbhm_receive_data(Cbhm_Glib_Info *info) receive_data_done: g_source_remove_poll(&info->gsource, &info->datafd); + close(info->datafd.fd); info->datafd.fd = -1; info->data_receive = false; - close(info->pipe[1]); _cbhm_set_selection(info); } @@ -515,11 +514,11 @@ _data_device_cb_selection(void *data, struct wl_data_device *data_device, struct if (offer == NULL) { INF("[CBHM]_data_device_cb_selection: previous selection cancelled\n"); if (info->data_receive == true) { - WRN("[CBHM]_data_device_cb_selection: stop receive(%d, %d)\n", info->datafd.fd, info->pipe[1]); + WRN("[CBHM]_data_device_cb_selection: stop receive(%d)\n", info->datafd.fd); g_source_remove_poll(&info->gsource, &info->datafd); + close(info->datafd.fd); info->datafd.fd = -1; info->data_receive = false; - close(info->pipe[1]); } } if (cbhm_data_offer->data_offer != offer) { @@ -554,6 +553,7 @@ _data_device_cb_selection(void *data, struct wl_data_device *data_device, struct info->received_data = NULL; wl_data_offer_receive(offer, (const char *)mime_type, pipe[1]); + close(pipe[1]); wl_display_flush(info->wl_disp); @@ -566,8 +566,6 @@ _data_device_cb_selection(void *data, struct wl_data_device *data_device, struct g_source_add_poll(&info->gsource, &info->datafd); DBG("[CBHM]_data_device_cb_selection: set datafd(%d, %d)\n", pipe[0], pipe[1]); - info->pipe[0] = pipe[0]; - info->pipe[1] = pipe[1]; } static const struct wl_data_device_listener _data_device_listener = @@ -861,8 +859,8 @@ cbhm_gsource_finalize(GSource *source) } info->cbhm_data_offer = NULL; if (info->datafd.fd != -1) { + close(info->datafd.fd); info->datafd.fd = -1; - close(info->pipe[1]); } cbhm_wayland_shutdown(info); g_source_destroy(source); @@ -940,8 +938,8 @@ cbhm_shutdown(GSource *gsource) } info->cbhm_data_offer = NULL; if (info->datafd.fd != -1) { + close(info->datafd.fd); info->datafd.fd = -1; - close(info->pipe[1]); } cbhm_wayland_shutdown(info); -- 2.7.4