aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTudor Brindus <me@tbrindus.ca>2021-01-30 14:58:27 -0500
committerSimon Ser <contact@emersion.fr>2021-01-31 19:17:04 +0100
commitb3d782f81877088da496006892f8522299e40ccb (patch)
tree43f605965f0f64e0882583e7bd2897e1135879db
parentaa86a022fa00edd0723ff48a6765ee7fbddefadc (diff)
xwayland/selection: introduce `xwm_selection_transfer_init`
Currently, all this does is initialize `wl_client_fd` to -1, so that comparisons with 0 are meaningful.
-rw-r--r--include/xwayland/selection.h1
-rw-r--r--xwayland/selection/incoming.c4
-rw-r--r--xwayland/selection/outgoing.c1
-rw-r--r--xwayland/selection/selection.c5
4 files changed, 9 insertions, 2 deletions
diff --git a/include/xwayland/selection.h b/include/xwayland/selection.h
index 43d59054..8b171e1e 100644
--- a/include/xwayland/selection.h
+++ b/include/xwayland/selection.h
@@ -47,6 +47,7 @@ void xwm_selection_transfer_close_wl_client_fd(
struct wlr_xwm_selection_transfer *transfer);
void xwm_selection_transfer_destroy_property_reply(
struct wlr_xwm_selection_transfer *transfer);
+void xwm_selection_transfer_init(struct wlr_xwm_selection_transfer *transfer);
void xwm_selection_transfer_finish(struct wlr_xwm_selection_transfer *transfer);
bool xwm_selection_transfer_get_selection_property(
struct wlr_xwm_selection_transfer *transfer, bool delete);
diff --git a/xwayland/selection/incoming.c b/xwayland/selection/incoming.c
index e41d1287..183d5f88 100644
--- a/xwayland/selection/incoming.c
+++ b/xwayland/selection/incoming.c
@@ -155,7 +155,7 @@ static void source_send(struct wlr_xwm_selection *selection,
// lose track of the current `transfer->wl_client_fd` and use-after-free
// during cleanup. This doesn't happen often, but bail now to avoid a
// compositor crash later.
- if (transfer->wl_client_fd > 0) {
+ if (transfer->wl_client_fd >= 0) {
wlr_log(WLR_ERROR, "source_send fd %d, but %d already in progress", fd,
transfer->wl_client_fd);
if (transfer->wl_client_fd != fd) {
@@ -404,7 +404,7 @@ void xwm_handle_selection_notify(struct wlr_xwm *xwm,
wlr_log(WLR_DEBUG, "denying write access to clipboard: "
"no xwayland surface focused");
// Would leak this transfer otherwise. Should never happen.
- assert(selection->incoming.wl_client_fd <= 0);
+ assert(selection->incoming.wl_client_fd < 0);
return;
}
diff --git a/xwayland/selection/outgoing.c b/xwayland/selection/outgoing.c
index 1e490adb..8074e3a7 100644
--- a/xwayland/selection/outgoing.c
+++ b/xwayland/selection/outgoing.c
@@ -297,6 +297,7 @@ static bool xwm_selection_send_data(struct wlr_xwm_selection *selection,
return false;
}
+ xwm_selection_transfer_init(transfer);
transfer->selection = selection;
transfer->request = *req;
wl_array_init(&transfer->source_data);
diff --git a/xwayland/selection/selection.c b/xwayland/selection/selection.c
index 64c957b7..08d04178 100644
--- a/xwayland/selection/selection.c
+++ b/xwayland/selection/selection.c
@@ -32,6 +32,10 @@ void xwm_selection_transfer_destroy_property_reply(
transfer->property_reply = NULL;
}
+void xwm_selection_transfer_init(struct wlr_xwm_selection_transfer *transfer) {
+ transfer->wl_client_fd = -1;
+}
+
void xwm_selection_transfer_finish(
struct wlr_xwm_selection_transfer *transfer) {
transfer->incr = false;
@@ -182,6 +186,7 @@ static void selection_init(struct wlr_xwm *xwm,
selection->window = xwm->selection_window;
selection->incoming.selection = selection;
wl_list_init(&selection->outgoing);
+ xwm_selection_transfer_init(&selection->incoming);
uint32_t mask =
XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER |