selection: fix use-after-free crash from duplicate handler delete

This commit is contained in:
Ollie 2026-05-28 21:42:02 +02:00
parent 2b692a34f1
commit f2b4d25b81
1 changed files with 13 additions and 23 deletions

View File

@ -360,30 +360,20 @@ Bool WMCreateSelectionHandler(WMView * view, WMNativeAtom selection, Time timest
/* On Wayland (no X11 SelectionRequest events), immediately push
* the selection data via the clipboard store path so external
* clients can paste it. The data is fetched from the view's
* convertSelection callback. */
/* On Wayland (no X11 SelectionRequest events), push selection data
* to the compositor via the clipboard store path. If a handler
* already exists for this view+selection, just push fresh data
* so selection is always current (otherwise double-click to
* reselect would be skipped since ownsSelection is stale). */
if (vb->selection_fetch) {
/* Delete any existing handler for this view+selection first */
WMDeleteSelectionHandler(view, selection, WM_CURRENT_TIME);
if (handler->procs.convertSelection) {
WMNativeAtom textAtom = XA_STRING;
WMNativeAtom type;
WMData *d = handler->procs.convertSelection(handler->view,
selection, textAtom, handler->data, &type);
if (d) {
if (view->screen->viewBackend->clipboard_store) {
view->screen->viewBackend->clipboard_store(
view->screen->viewBackendCtx,
WMDataBytes(d),
WMGetDataLength(d));
}
WMReleaseData(d);
* clients can paste it. */
if (vb->selection_fetch && handler->procs.convertSelection) {
WMNativeAtom textAtom = XA_STRING;
WMNativeAtom type;
WMData *d = handler->procs.convertSelection(handler->view,
selection, textAtom, handler->data, &type);
if (d) {
if (view->screen->viewBackend->clipboard_store) {
view->screen->viewBackend->clipboard_store(
view->screen->viewBackendCtx,
WMDataBytes(d),
WMGetDataLength(d));
}
WMReleaseData(d);
}
}