diff options
author | rowanbeentje <rowan@beent.je> | 2010-01-27 01:04:03 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-01-27 01:04:03 +0000 |
commit | b36564545f2290e7e41a794c33783e6ce322bbcc (patch) | |
tree | 34dae44e3fd56b88154e8411e0b43407b0c7fb76 | |
parent | 9987c0cb9440fea045d56ece1dd8cdd0828c9820 (diff) | |
download | sequelpro-b36564545f2290e7e41a794c33783e6ce322bbcc.tar.gz sequelpro-b36564545f2290e7e41a794c33783e6ce322bbcc.tar.bz2 sequelpro-b36564545f2290e7e41a794c33783e6ce322bbcc.zip |
- Fix SSH threads (and connections) which were never cleaned up or closed, probably as a result of r1709
- Improve SSH and object cleanup, especially for cases where the connection drops, to ensure the connection proxy is cleaned up and all memory released
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 29 | ||||
-rw-r--r-- | Source/SPConnectionDelegate.m | 4 | ||||
-rw-r--r-- | Source/SPSSHTunnel.m | 3 |
3 files changed, 22 insertions, 14 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 7a3c9c8c..d112189f 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -103,6 +103,7 @@ static BOOL sTruncateLongFieldInLogs = YES; lastQueryExecutedAtTime = CGFLOAT_MAX; queryCancelled = NO; queryCancelUsedReconnect = NO; + serverVersionString = nil; // Initialize ivar defaults connectionTimeout = 10; @@ -372,20 +373,13 @@ static BOOL sTruncateLongFieldInLogs = YES; } mConnected = NO; - + if (connectionProxy) { [connectionProxy disconnect]; } - if (serverVersionString != nil) { - [serverVersionString release]; - serverVersionString = nil; - } - - if (theDbStructure != nil) { - [theDbStructure release]; - theDbStructure = nil; - } + if (serverVersionString) [serverVersionString release], serverVersionString = nil; + if (theDbStructure) [theDbStructure release], theDbStructure = nil; [self stopKeepAliveTimer]; } @@ -2382,12 +2376,25 @@ void performThreadedKeepAlive(void *ptr) { delegate = nil; + // Release the query lock, after unlocking it + [queryLock tryLock]; + [queryLock unlock]; + [queryLock release]; + + // Clean up connections if necessary + if (mConnected) [self disconnect]; + if (connectionProxy) { + [connectionProxy setConnectionStateChangeSelector:NULL delegate:nil]; + [connectionProxy disconnect]; + } + if (lastQueryErrorMessage) [lastQueryErrorMessage release]; if (connectionHost) [connectionHost release]; if (connectionLogin) [connectionLogin release]; if (connectionSocket) [connectionSocket release]; if (connectionPassword) [connectionPassword release]; - [queryLock release]; + if (serverVersionString) [serverVersionString release], serverVersionString = nil; + if (theDbStructure) [theDbStructure release], theDbStructure = nil; [super dealloc]; } diff --git a/Source/SPConnectionDelegate.m b/Source/SPConnectionDelegate.m index ff0cca23..fea894b6 100644 --- a/Source/SPConnectionDelegate.m +++ b/Source/SPConnectionDelegate.m @@ -118,7 +118,7 @@ // If 'disconnect' was selected, trigger a window close. if (connectionErrorCode == MCPConnectionCheckDisconnect) { - [self performSelectorOnMainThread:@selector(closeConnection) withObject:nil waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(closeDocumentWindowAndDisconnect:) withObject:nil waitUntilDone:YES]; } return connectionErrorCode; @@ -130,7 +130,7 @@ * everything up before it's all deallocated as a result of the close. * Also sets alpha to fully transparent so accidental dialogs are hidden! */ -- (void) closeConnection +- (void) closeDocumentWindowAndDisconnect { _isConnected = NO; [self windowWillClose:nil]; diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m index f74804ca..4779e6a1 100644 --- a/Source/SPSSHTunnel.m +++ b/Source/SPSSHTunnel.m @@ -59,7 +59,7 @@ // Set up a connection for use by the tunnel process tunnelConnectionName = [[NSString alloc] initWithFormat:@"SequelPro-%lu", (unsigned long)[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]]; tunnelConnectionVerifyHash = [[NSString alloc] initWithFormat:@"%lu", (unsigned long)[[NSString stringWithFormat:@"%f-seeded", [[NSDate date] timeIntervalSince1970]] hash]]; - tunnelConnection = [[NSConnection defaultConnection] retain]; + tunnelConnection = [NSConnection new]; [tunnelConnection runInNewThread]; [tunnelConnection removeRunLoop:[NSRunLoop currentRunLoop]]; [tunnelConnection setRootObject:self]; @@ -593,6 +593,7 @@ [remoteHost release]; [tunnelConnectionName release]; [tunnelConnectionVerifyHash release]; + [tunnelConnection invalidate]; [tunnelConnection release]; [debugMessages release]; if (password) [password release]; |