From 07d267b5bc9adb6825f004c302d28ffe209ec6e3 Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Sat, 9 May 2026 13:20:48 +0000 Subject: [PATCH] fix(ai): protect window validation with mutex The existence check accesses shared state without synchronization, which can cause race conditions when called from background threads. Explicitly locking the mutex ensures safe access during validation. --- src/ai/ai_client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ai/ai_client.c b/src/ai/ai_client.c index 5fc2ac7a..ffa3947d 100644 --- a/src/ai/ai_client.c +++ b/src/ai/ai_client.c @@ -90,7 +90,10 @@ _aiwin_validate(gpointer user_data) return NULL; } - if (!wins_ai_exists((ProfAiWin*)user_data)) { + pthread_mutex_lock(&lock); + gboolean win_exists = wins_ai_exists((ProfAiWin*)user_data); + pthread_mutex_unlock(&lock); + if (!win_exists) { log_warning("[AI-THREAD] aiwin=%p no longer exists — window was closed", (void*)user_data); return NULL; }