From 98deec9ec0a048cd5fb99076f40253cc387b4864 Mon Sep 17 00:00:00 2001
From: akallabeth <akallabeth@posteo.net>
Date: Wed, 31 Dec 2025 15:43:12 +0100
Subject: [PATCH] [client,sdl] lock primary while used

---
 client/SDL/SDL3/sdl_freerdp.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Index: FreeRDP-3.10.3/client/SDL/SDL3/sdl_freerdp.cpp
===================================================================
--- FreeRDP-3.10.3.orig/client/SDL/SDL3/sdl_freerdp.cpp
+++ FreeRDP-3.10.3/client/SDL/SDL3/sdl_freerdp.cpp
@@ -397,6 +397,7 @@ static BOOL sdl_draw_to_window(SdlContex
 	auto gdi = context->gdi;
 
 	auto size = window.rect();
+    std::unique_lock lock(sdl->critical);
 
 	if (!freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing))
 	{
@@ -685,7 +686,7 @@ static void sdl_cleanup_sdl(SdlContext*
 	if (!sdl)
 		return;
 
-	std::lock_guard<CriticalSection> lock(sdl->critical);
+    std::unique_lock lock(sdl->critical);
 	sdl->windows.clear();
 	sdl->connection_dialog.reset();
 
@@ -790,7 +791,7 @@ static BOOL sdl_wait_create_windows(SdlC
 
 static bool shall_abort(SdlContext* sdl)
 {
-	std::lock_guard<CriticalSection> lock(sdl->critical);
+    std::unique_lock lock(sdl->critical);
 	if (freerdp_shall_disconnect_context(sdl->context()))
 	{
 		if (sdl->rdp_thread_running)
@@ -846,7 +847,7 @@ static int sdl_run(SdlContext* sdl)
 			SDL_Log("got event %s [0x%08" PRIx32 "]", sdl_event_type_str(windowEvent.type),
 			        windowEvent.type);
 #endif
-			std::lock_guard<CriticalSection> lock(sdl->critical);
+            std::unique_lock lock(sdl->critical);
 			/* The session might have been disconnected while we were waiting for a new SDL event.
 			 * In that case ignore the SDL event and terminate. */
 			if (freerdp_shall_disconnect_context(sdl->context()))
