diff options
-rw-r--r-- | Source/SPSSHTunnel.h | 1 | ||||
-rw-r--r-- | Source/SPSSHTunnel.m | 14 |
2 files changed, 13 insertions, 2 deletions
diff --git a/Source/SPSSHTunnel.h b/Source/SPSSHTunnel.h index 27522d90..9230f7e1 100644 --- a/Source/SPSSHTunnel.h +++ b/Source/SPSSHTunnel.h @@ -52,6 +52,7 @@ NSString *keychainAccount; NSString *requestedPassphrase; NSMutableArray *debugMessages; + NSLock *debugMessagesLock; BOOL useHostFallback; BOOL requestedResponse; BOOL passwordInKeychain; diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m index dfeb2f16..eeef83d2 100644 --- a/Source/SPSSHTunnel.m +++ b/Source/SPSSHTunnel.m @@ -56,6 +56,7 @@ stateChangeSelector = nil; lastError = nil; debugMessages = [[NSMutableArray alloc] init]; + debugMessagesLock = [[NSLock alloc] init]; answerAvailableLock = [[NSLock alloc] init]; // Set up a connection for use by the tunnel process @@ -164,7 +165,10 @@ * by line endings. */ - (NSString *) debugMessages { - return [debugMessages componentsJoinedByString:@"\n"]; + [debugMessagesLock lock]; + NSString *debugMessagesString = [debugMessages componentsJoinedByString:@"\n"]; + [debugMessagesLock unlock]; + return debugMessagesString; } /* @@ -175,7 +179,9 @@ localPort = 0; if (connectionState != PROXY_STATE_IDLE) return; + [debugMessagesLock lock]; [debugMessages removeAllObjects]; + [debugMessagesLock unlock]; [NSThread detachNewThreadSelector:@selector(launchTask:) toTarget: self withObject: nil ]; } @@ -369,7 +375,8 @@ } /* - * Processes messages recieved from the SSH task + * Processes messages recieved from the SSH task. These may be received singly + * or several stuck together. */ - (void)standardErrorHandler:(NSNotification*)aNotification { @@ -385,7 +392,9 @@ enumerator = [messages objectEnumerator]; while (message = [[enumerator nextObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]) { if (![message length]) continue; + [debugMessagesLock lock]; [debugMessages addObject:[NSString stringWithString:message]]; + [debugMessagesLock unlock]; if ([message rangeOfString:@"Entering interactive session."].location != NSNotFound) { connectionState = PROXY_STATE_CONNECTED; @@ -625,6 +634,7 @@ [tunnelConnection invalidate]; [tunnelConnection release]; [debugMessages release]; + [debugMessagesLock release]; [answerAvailableLock tryLock]; [answerAvailableLock unlock]; [answerAvailableLock release]; |