From d3e8b3b9365be96a4f11dda149d71b3287227d0a Mon Sep 17 00:00:00 2001
From: Armin Novak <armin.novak@thincast.com>
Date: Mon, 9 Feb 2026 17:52:37 +0100
Subject: [PATCH] [client,x11] lock cache when providing data

---
 client/X11/xf_cliprdr.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Index: FreeRDP-3.10.3/client/X11/xf_cliprdr.c
===================================================================
--- FreeRDP-3.10.3.orig/client/X11/xf_cliprdr.c
+++ FreeRDP-3.10.3/client/X11/xf_cliprdr.c
@@ -1572,12 +1572,16 @@ static BOOL xf_cliprdr_process_selection
 			dstFormatId = get_dst_format_id_for_local_request(clipboard, cformat);
 			DEBUG_CLIPRDR("formatId: %u, dstFormatId: %u", formatId, dstFormatId);
 
+			wHashTable* table = clipboard->cachedData;
+			if (rawTransfer)
+				table = clipboard->cachedRawData;
+
+			HashTable_Lock(table);
+
 			if (!rawTransfer)
-				cached_data = HashTable_GetItemValue(clipboard->cachedData,
-				                                     format_to_cache_slot(dstFormatId));
+				cached_data = HashTable_GetItemValue(table, format_to_cache_slot(dstFormatId));
 			else
-				cached_data = HashTable_GetItemValue(clipboard->cachedRawData,
-				                                     format_to_cache_slot(formatId));
+				cached_data = HashTable_GetItemValue(table, format_to_cache_slot(formatId));
 
 			DEBUG_CLIPRDR("hasCachedData: %u, rawTransfer: %u", cached_data ? 1 : 0, rawTransfer);
 
@@ -1631,6 +1635,7 @@ static BOOL xf_cliprdr_process_selection
 				delayRespond = TRUE;
 				xf_cliprdr_send_data_request(clipboard, formatId, cformat);
 			}
+			HashTable_Unlock(table);
 		}
 	}
 
