diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp
index 64642efd9377961541a733b72e8a97c601b62b50..687ae1e6f445d7face430f7d8874e754c365b457 100644
--- a/src/sbbs3/main.cpp
+++ b/src/sbbs3/main.cpp
@@ -771,6 +771,11 @@ void input_thread(void *arg)
 			break;
 		}
 
+		if(sbbs->client_socket==INVALID_SOCKET) {
+			pthread_mutex_unlock(&sbbs->input_thread_mutex);
+			break;
+		}
+
     	rd=RingBufFree(&sbbs->inbuf);
 
 		if(!rd) { // input buffer full