[Spice-devel] [PATCH vdagent-linux] clipboard: cancel request for targets on grab from client

Jakub Janků jjanku at redhat.com
Sun Feb 17 20:21:11 UTC 2019


If gtk_clipboard_set_with_data() is invoked between
gtk_clipboard_request_targets() and the
GtkClipboardTargetsReceivedFunc callback,
the targets we eventually receive are no longer valid.

To solve this, cancel the request in vdagent_clipboard_grab().

Otherwise we end up in a situation when vdagent holds
clipboard grab in the guest but cannot provide data to the
apps that request it - this can be observed in the log:

    CRITICAL **: 20:48:55.782: clipboard_get_cb: assertion 'c->selections[sel_id].owner == OWNER_CLIENT' failed

Signed-off-by: Jakub Janků <jjanku at redhat.com>
---

The same bug is present in spice-gtk as well as
in the X11 implementation of clipboard in vdagent.

I'm planing on sending a fix for spice-gtk later
(possibly with other patches).

I decided not to fix the X11 clipboard in vdagent
as I'm hoping it could be removed with the next release.
If you think it should get fixed  too, let me know.

---
 src/vdagent/clipboard.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/vdagent/clipboard.c b/src/vdagent/clipboard.c
index 6b01a7b..a8d2e91 100644
--- a/src/vdagent/clipboard.c
+++ b/src/vdagent/clipboard.c
@@ -304,6 +304,7 @@ void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
     vdagent_x11_clipboard_grab(c->x11, sel_id, types, n_types);
 #else
     GtkTargetEntry targets[G_N_ELEMENTS(atom2agent)];
+    Selection *sel;
     guint n_targets, i, t;
 
     g_return_if_fail(sel_id < SELECTION_COUNT);
@@ -322,7 +323,13 @@ void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
         return;
     }
 
-    if (gtk_clipboard_set_with_data(c->selections[sel_id].clipboard,
+    sel = &c->selections[sel_id];
+
+    if (sel->last_targets_req) {
+        g_clear_pointer(&sel->last_targets_req, request_ref_cancel);
+    }
+
+    if (gtk_clipboard_set_with_data(sel->clipboard,
                                     targets, n_targets,
                                     clipboard_get_cb, clipboard_clear_cb, c))
         clipboard_new_owner(c, sel_id, OWNER_CLIENT);
-- 
2.20.1



More information about the Spice-devel mailing list