diff --git a/src/sbbs3/xtrn.cpp b/src/sbbs3/xtrn.cpp
index 80641ce632bdbbe259a728fc7a62e0abda426f95..24c903683d8dd727ff7e330c021f94fa4729c59f 100644
--- a/src/sbbs3/xtrn.cpp
+++ b/src/sbbs3/xtrn.cpp
@@ -253,7 +253,6 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir)
     bool	was_online=true;
 	bool	rio_abortable_save;
 	bool	use_pipes=false;	// NT-compatible console redirection
-	bool	input_thread_mutex_locked=false;
 	uint	i;
     time_t	hungup=0;
 	HANDLE	vxd=INVALID_HANDLE_VALUE;
@@ -556,10 +555,8 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir)
 		fclose(fp);
 
 		/* not temporary */
-		if(!(mode&EX_INR)) {
+		if(!(mode&EX_INR))
 			pthread_mutex_lock(&input_thread_mutex);
-			input_thread_mutex_locked=true;
-		}
 	}
 
     if(!CreateProcess(
@@ -575,8 +572,7 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir)
 		&process_info  	// pointer to PROCESS_INFORMATION
 		)) {
 		XTRN_CLEANUP;
-		if(input_thread_mutex_locked)
-			pthread_mutex_unlock(&input_thread_mutex);
+		pthread_mutex_unlock(&input_thread_mutex);
 		SetLastError(last_error);	/* Restore LastError */
         errormsg(WHERE, ERR_EXEC, realcmdline, mode);
         return(GetLastError());
@@ -924,8 +920,7 @@ int sbbs_t::external(char* cmdline, long mode, char* startup_dir)
 		if(native) {
 			ulong l=0;
 			ioctlsocket(client_socket, FIONBIO, &l);
-			if(input_thread_mutex_locked)
-				pthread_mutex_unlock(&input_thread_mutex);
+			pthread_mutex_unlock(&input_thread_mutex);
 		}
 
 		curatr=~0;			// Can't guarantee current attributes
diff --git a/src/xpdev/threadwrap.h b/src/xpdev/threadwrap.h
index accb941133ebffc187966ebeef838a50a4280801..62b87aff527a787507a807170dd98346507a2a10 100644
--- a/src/xpdev/threadwrap.h
+++ b/src/xpdev/threadwrap.h
@@ -74,7 +74,7 @@ extern "C" {
 	typedef CRITICAL_SECTION pthread_mutex_t;
 	#define pthread_mutex_init(pmtx,v)	InitializeCriticalSection(pmtx)
 	#define pthread_mutex_lock(pmtx)	EnterCriticalSection(pmtx)
-	#define pthread_mutex_unlock(pmtx)	LeaveCriticalSection(pmtx)
+	#define pthread_mutex_unlock(pmtx)	if((pmtx)->LockCount) LeaveCriticalSection(pmtx)
 	#define	pthread_mutex_destroy(pmtx)	DeleteCriticalSection(pmtx)
 #else	/* Implemented as Win32 Mutexes (much slower) */
 	typedef HANDLE pthread_mutex_t;