From b36564545f2290e7e41a794c33783e6ce322bbcc Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 27 Jan 2010 01:04:03 +0000 Subject: - 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 --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'Frameworks') 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]; } -- cgit v1.2.3