x11: fix deadlock when finalizing output stream

If we have a very large selection (many MB of textbuffer text) we can
possibly deadlock here trying to flush as the serializer is disposed
and finalized on the main thread.

This avoids it similarly to other places by checking that we are allowed
to flush at this point.

Fixes: #3153
This commit is contained in:
Christian Hergert
2020-09-11 14:38:24 -07:00
parent e55bdf87b5
commit ccf44b694b

View File

@@ -439,7 +439,11 @@ gdk_x11_selection_output_stream_flush (GOutputStream *output_stream,
g_main_context_invoke (NULL, gdk_x11_selection_output_stream_invoke_flush, stream);
g_mutex_lock (&priv->mutex);
if (gdk_x11_selection_output_stream_needs_flush_unlocked (stream))
/* We have to check gdk_x11_selection_output_stream_can_flush() because if
* we cannot, nothing will necessarily complete our g_cond_wait().
*/
if (!priv->delete_pending &&
gdk_x11_selection_output_stream_needs_flush_unlocked (stream))
g_cond_wait (&priv->cond, &priv->mutex);
g_mutex_unlock (&priv->mutex);