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.
This commit is contained in:
Tudor Brindus 2021-01-30 14:58:27 -05:00 committed by Simon Ser
parent aa86a022fa
commit b3d782f818
4 changed files with 9 additions and 2 deletions

View file

@ -47,6 +47,7 @@ void xwm_selection_transfer_close_wl_client_fd(
struct wlr_xwm_selection_transfer *transfer); struct wlr_xwm_selection_transfer *transfer);
void xwm_selection_transfer_destroy_property_reply( void xwm_selection_transfer_destroy_property_reply(
struct wlr_xwm_selection_transfer *transfer); 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); void xwm_selection_transfer_finish(struct wlr_xwm_selection_transfer *transfer);
bool xwm_selection_transfer_get_selection_property( bool xwm_selection_transfer_get_selection_property(
struct wlr_xwm_selection_transfer *transfer, bool delete); struct wlr_xwm_selection_transfer *transfer, bool delete);

View file

@ -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 // 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 // during cleanup. This doesn't happen often, but bail now to avoid a
// compositor crash later. // 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, wlr_log(WLR_ERROR, "source_send fd %d, but %d already in progress", fd,
transfer->wl_client_fd); transfer->wl_client_fd);
if (transfer->wl_client_fd != 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: " wlr_log(WLR_DEBUG, "denying write access to clipboard: "
"no xwayland surface focused"); "no xwayland surface focused");
// Would leak this transfer otherwise. Should never happen. // Would leak this transfer otherwise. Should never happen.
assert(selection->incoming.wl_client_fd <= 0); assert(selection->incoming.wl_client_fd < 0);
return; return;
} }

View file

@ -297,6 +297,7 @@ static bool xwm_selection_send_data(struct wlr_xwm_selection *selection,
return false; return false;
} }
xwm_selection_transfer_init(transfer);
transfer->selection = selection; transfer->selection = selection;
transfer->request = *req; transfer->request = *req;
wl_array_init(&transfer->source_data); wl_array_init(&transfer->source_data);

View file

@ -32,6 +32,10 @@ void xwm_selection_transfer_destroy_property_reply(
transfer->property_reply = NULL; 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( void xwm_selection_transfer_finish(
struct wlr_xwm_selection_transfer *transfer) { struct wlr_xwm_selection_transfer *transfer) {
transfer->incr = false; transfer->incr = false;
@ -182,6 +186,7 @@ static void selection_init(struct wlr_xwm *xwm,
selection->window = xwm->selection_window; selection->window = xwm->selection_window;
selection->incoming.selection = selection; selection->incoming.selection = selection;
wl_list_init(&selection->outgoing); wl_list_init(&selection->outgoing);
xwm_selection_transfer_init(&selection->incoming);
uint32_t mask = uint32_t mask =
XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER | XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER |