Fix pipe fd management error 31/298731/1
authorJunkyeong Kim <jk0430.kim@samsung.com>
Wed, 13 Sep 2023 05:17:29 +0000 (14:17 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Wed, 13 Sep 2023 05:17:33 +0000 (14:17 +0900)
Change-Id: Ida7802e0a8dd9889612b95dae2b00056c80e8987
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
src/cbhm.c

index 59f693a..8bae588 100644 (file)
@@ -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);