From 22536190599f3a73573309d2322b4ddc8f3a5091 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Fri, 3 Jan 2025 13:34:22 -0500
Subject: [PATCH] Move ssh_complete out of ssh_mutex

Coverity seems to hate it mostly in the mutex, so change it to
mostly outside of the mutex and see if that's fine.

It doesn't really matter where it's changed as it's an atomic bool.
---
 src/syncterm/ssh.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/syncterm/ssh.c b/src/syncterm/ssh.c
index b647695f6a..1da43bbecf 100644
--- a/src/syncterm/ssh.c
+++ b/src/syncterm/ssh.c
@@ -173,8 +173,8 @@ ssh_input_thread(void *args)
 		sftp_do_finish = false;
 		pthread_mutex_lock(&ssh_mutex);
 		if (FlushData(ssh_session) == CRYPT_ERROR_COMPLETE) {
-			ssh_complete = true;
 			pthread_mutex_unlock(&ssh_mutex);
+			ssh_complete = true;
 			break;
 		}
 		if (ssh_channel != -1) {
@@ -189,10 +189,10 @@ ssh_input_thread(void *args)
 		}
 		if (ssh_channel == -1 && sftp_channel == -1) {
 			both_gone = true;
-			ssh_complete = true;
 		}
 		pthread_mutex_unlock(&ssh_mutex);
 		if (both_gone) {
+			ssh_complete = true;
 			break;
 		}
 		if (sftp_do_finish) {
@@ -204,8 +204,8 @@ ssh_input_thread(void *args)
 
 		pthread_mutex_lock(&ssh_mutex);
 		if (FlushData(ssh_session) == CRYPT_ERROR_COMPLETE) {
-			ssh_complete = true;
 			pthread_mutex_unlock(&ssh_mutex);
+			ssh_complete = true;
 			break;
 		}
 
@@ -223,8 +223,8 @@ ssh_input_thread(void *args)
 			}
 		}
 		if (ssh_channel == -1 && sftp_channel == -1) {
-			ssh_complete = true;
 			pthread_mutex_unlock(&ssh_mutex);
+			ssh_complete = true;
 			break;
 		}
 
@@ -332,8 +332,8 @@ ssh_output_thread(void *args)
 				ret = 0;
 				pthread_mutex_lock(&ssh_mutex);
 				if (ssh_channel == -1) {
-					ssh_complete = true;
 					pthread_mutex_unlock(&ssh_mutex);
+					ssh_complete = true;
 					channel_gone = true;
 					break;
 				}
@@ -345,8 +345,8 @@ ssh_output_thread(void *args)
 						FlushData(ssh_session);
 				}
 				if (cryptStatusError(status)) {
-					ssh_complete = true;
 					pthread_mutex_unlock(&ssh_mutex);
+					ssh_complete = true;
 					if ((status == CRYPT_ERROR_COMPLETE) || (status == CRYPT_ERROR_NOTFOUND)) { /* connection closed */
 						channel_gone = true;
 						break;
-- 
GitLab