From 58409406afe7c2a8a71ed2dc8e22075be4f41c0c Mon Sep 17 00:00:00 2001
From: Armin Novak <armin.novak@thincast.com>
Date: Mon, 9 Feb 2026 12:58:42 +0100
Subject: [PATCH] [client,X11] fix clipboard update

Synchronize channel thread with RDP thread when accessing clipboard
formats
---
 client/X11/xf_cliprdr.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Index: freerdp-2.11.7/client/X11/xf_cliprdr.c
===================================================================
--- freerdp-2.11.7.orig/client/X11/xf_cliprdr.c
+++ freerdp-2.11.7/client/X11/xf_cliprdr.c
@@ -577,7 +577,11 @@ static BOOL xf_clipboard_changed(xfClipb
 
 static void xf_clipboard_formats_free(xfClipboard* clipboard)
 {
+	/* Synchronize RDP/X11 thread with channel thread */
+	xf_lock_x11(clipboard->xfc);
 	xf_cliprdr_free_formats(clipboard->lastSentFormats, clipboard->lastSentNumFormats);
+	xf_unlock_x11(clipboard->xfc);
+
 	clipboard->lastSentFormats = NULL;
 	clipboard->lastSentNumFormats = 0;
 }
@@ -1254,15 +1258,16 @@ static UINT xf_cliprdr_monitor_ready(Cli
                                      const CLIPRDR_MONITOR_READY* monitorReady)
 {
 	xfClipboard* clipboard = (xfClipboard*)context->custom;
-	UINT ret;
 
 	WINPR_UNUSED(monitorReady);
 
-	if ((ret = xf_cliprdr_send_client_capabilities(clipboard)) != CHANNEL_RC_OK)
+	const UINT ret = xf_cliprdr_send_client_capabilities(clipboard);
+	if (ret != CHANNEL_RC_OK)
 		return ret;
 
-	if ((ret = xf_cliprdr_send_client_format_list(clipboard)) != CHANNEL_RC_OK)
-		return ret;
+	const UINT ret2 = xf_cliprdr_send_client_format_list(clipboard);
+	if (ret2 != CHANNEL_RC_OK)
+		return ret2;
 
 	clipboard->sync = TRUE;
 	return CHANNEL_RC_OK;
