[Spice-devel] [PATCH spice-gtk] gtk-session: avoid mainloop recursion in clipboard_get

Christophe Fergeau cfergeau at redhat.com
Thu Oct 10 17:53:00 CEST 2013


On Thu, Oct 10, 2013 at 05:47:03PM +0200, Marc-André Lureau wrote:
> clipboard_get() exits when the clipboard data is received, or when the
> agent connection state change. However, if the agent is already
> disconnected, neither of those 2 conditions can be reached.
> 
> Check agent is connected before running loop, exit early if not.

"Check if the agent is connected before running the loop"

ACK.

> ---
>  gtk/spice-gtk-session.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
> index af491d2..71ed300 100644
> --- a/gtk/spice-gtk-session.c
> +++ b/gtk/spice-gtk-session.c
> @@ -615,6 +615,7 @@ static void clipboard_get(GtkClipboard *clipboard,
>      RunInfo ri = { NULL, };
>      SpiceGtkSession *self = user_data;
>      SpiceGtkSessionPrivate *s = self->priv;
> +    gboolean agent_connected = FALSE;
>      gulong clipboard_handler;
>      gulong agent_handler;
>      int selection;
> @@ -642,12 +643,20 @@ static void clipboard_get(GtkClipboard *clipboard,
>      spice_main_clipboard_selection_request(s->main, selection,
>                                             atom2agent[info].vdagent);
>  
> +
> +    g_object_get(s->main, "agent-connected", &agent_connected, NULL);
> +    if (!agent_connected) {
> +        SPICE_DEBUG("canceled clipboard_get, before running loop");
> +        goto cleanup;
> +    }
> +
>      /* apparently, this is needed to avoid dead-lock, from
>         gtk_dialog_run */
>      gdk_threads_leave();
>      g_main_loop_run(ri.loop);
>      gdk_threads_enter();
>  
> +cleanup:
>      g_main_loop_unref(ri.loop);
>      ri.loop = NULL;
>      g_signal_handler_disconnect(s->main, clipboard_handler);
> -- 
> 1.8.3.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20131010/4d2c5aff/attachment.pgp>


More information about the Spice-devel mailing list