From 13805614e6ed2131827bfa6c668b50a1b30da1e5 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 10 Feb 2010 01:32:05 +0000 Subject: Fix a number of memory leaks, and over-releases, as both a result of manual inspection of leaks and Clang static analysis. --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h | 2 +- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 40 ++++++++++++---------- Frameworks/MCPKit/MCPFoundationKit/MCPResult.m | 6 ++-- 3 files changed, 25 insertions(+), 23 deletions(-) (limited to 'Frameworks/MCPKit') diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h index 68875bb7..84b18a26 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h @@ -230,7 +230,7 @@ void performThreadedKeepAlive(void *ptr); - (MCPResult *)listFieldsFromTable:(NSString *)tableName like:(NSString *)fieldsName; - (void)queryDbStructure; - (NSDictionary *)getDbStructure; -- (NSInteger)getUniqueDbIndentifierFor:(NSString*)term; +- (NSInteger)getUniqueDbIdentifierFor:(NSString*)term; // Server information - (NSString *)clientInfo; diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 1911e1e1..8cb80048 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -111,6 +111,7 @@ static BOOL sTruncateLongFieldInLogs = YES; keepAliveInterval = 60; theDbStructure = nil; + uniqueDbIdentifier = nil; isQueryingDbStructure = NO; connectionThreadId = 0; @@ -281,7 +282,7 @@ static BOOL sTruncateLongFieldInLogs = YES; { const char *theLogin = [self cStringFromString:connectionLogin]; const char *theHost; - const char *thePass; + const char *thePass = NULL; const char *theSocket; void *theRet; @@ -380,6 +381,7 @@ static BOOL sTruncateLongFieldInLogs = YES; if (serverVersionString) [serverVersionString release], serverVersionString = nil; if (theDbStructure) [theDbStructure release], theDbStructure = nil; + if (uniqueDbIdentifier) [uniqueDbIdentifier release], uniqueDbIdentifier = nil; [self stopKeepAliveTimer]; } @@ -1375,6 +1377,7 @@ void performThreadedKeepAlive(void *ptr) // If this query has failed once already, check the connection if (isQueryRetry) { if (![self checkConnection]) { + if (queryErrorMessage) [queryErrorMessage release], queryErrorMessage = nil; // Notify that the query has been performed [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:delegate]; @@ -1536,7 +1539,7 @@ void performThreadedKeepAlive(void *ptr) if (killerConnection) { const char *theLogin = [self cStringFromString:connectionLogin]; const char *theHost; - const char *thePass; + const char *thePass = NULL; const char *theSocket; void *connectionSetupStatus; @@ -1658,7 +1661,7 @@ void performThreadedKeepAlive(void *ptr) { if (!mConnected) return NO; - MCPResult *theResult = [MCPResult alloc]; + MCPResult *theResult = nil; MYSQL_RES *theResPtr; [self stopKeepAliveTimer]; @@ -1670,20 +1673,20 @@ void performThreadedKeepAlive(void *ptr) [queryLock lock]; if ((dbsName == nil) || ([dbsName isEqualToString:@""])) { if (theResPtr = mysql_list_dbs(mConnection, NULL)) { - [theResult initWithResPtr: theResPtr encoding: mEncoding timeZone:mTimeZone]; + theResult = [[MCPResult alloc] initWithResPtr: theResPtr encoding: mEncoding timeZone:mTimeZone]; } else { - [theResult init]; + theResult = [[MCPResult alloc] init]; } } else { const char *theCDBsName = (const char *)[self cStringFromString:dbsName]; if (theResPtr = mysql_list_dbs(mConnection, theCDBsName)) { - [theResult initWithResPtr:theResPtr encoding:mEncoding timeZone:mTimeZone]; + theResult = [[MCPResult alloc] initWithResPtr:theResPtr encoding:mEncoding timeZone:mTimeZone]; } else { - [theResult init]; + theResult = [[MCPResult alloc] init]; } } [queryLock unlock]; @@ -1715,7 +1718,7 @@ void performThreadedKeepAlive(void *ptr) { if (!mConnected) return NO; - MCPResult *theResult = [MCPResult alloc]; + MCPResult *theResult = nil; MYSQL_RES *theResPtr; [self stopKeepAliveTimer]; @@ -1727,19 +1730,19 @@ void performThreadedKeepAlive(void *ptr) [queryLock lock]; if ((tablesName == nil) || ([tablesName isEqualToString:@""])) { if (theResPtr = mysql_list_tables(mConnection, NULL)) { - [theResult initWithResPtr: theResPtr encoding: mEncoding timeZone:mTimeZone]; + theResult = [[MCPResult alloc] initWithResPtr: theResPtr encoding: mEncoding timeZone:mTimeZone]; } else { - [theResult init]; + theResult = [[MCPResult alloc] init]; } } else { const char *theCTablesName = (const char *)[self cStringFromString:tablesName]; if (theResPtr = mysql_list_tables(mConnection, theCTablesName)) { - [theResult initWithResPtr: theResPtr encoding: mEncoding timeZone:mTimeZone]; + theResult = [[MCPResult alloc] initWithResPtr: theResPtr encoding: mEncoding timeZone:mTimeZone]; } else { - [theResult init]; + theResult = [[MCPResult alloc] init]; } } @@ -1818,7 +1821,7 @@ void performThreadedKeepAlive(void *ptr) if (structConnection) { const char *theLogin = [self cStringFromString:connectionLogin]; const char *theHost; - const char *thePass; + const char *thePass = NULL; const char *theSocket; void *connectionSetupStatus; @@ -1957,9 +1960,9 @@ void performThreadedKeepAlive(void *ptr) * Otherwise it return 0. Mainly used for completion to know whether a `foo`. can only be * a db name or a table name. */ -- (NSInteger)getUniqueDbIndentifierFor:(NSString*)term +- (NSInteger)getUniqueDbIdentifierFor:(NSString*)term { - if([uniqueDbIdentifier objectForKey:term]) + if(uniqueDbIdentifier && [uniqueDbIdentifier objectForKey:term]) return [[uniqueDbIdentifier objectForKey:term] integerValue]; else return 0; @@ -2017,15 +2020,15 @@ void performThreadedKeepAlive(void *ptr) */ - (MCPResult *)listProcesses { - MCPResult *theResult = [MCPResult alloc]; + MCPResult *theResult = nil; MYSQL_RES *theResPtr; [queryLock lock]; if (theResPtr = mysql_list_processes(mConnection)) { - [theResult initWithResPtr:theResPtr encoding:mEncoding timeZone:mTimeZone]; + theResult = [[MCPResult alloc] initWithResPtr:theResPtr encoding:mEncoding timeZone:mTimeZone]; } else { - [theResult init]; + theResult = [[MCPResult alloc] init]; } [queryLock unlock]; @@ -2395,6 +2398,7 @@ void performThreadedKeepAlive(void *ptr) if (connectionPassword) [connectionPassword release]; if (serverVersionString) [serverVersionString release], serverVersionString = nil; if (theDbStructure) [theDbStructure release], theDbStructure = nil; + if (uniqueDbIdentifier) [uniqueDbIdentifier release], uniqueDbIdentifier = nil; [super dealloc]; } diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m b/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m index 98f26b6c..4e3fef3a 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m @@ -866,7 +866,7 @@ const OUR_CHARSET our_charsets60[] = - (NSUInteger)fetchFlagsForKey:(NSString *)key { NSUInteger theRet; - NSUInteger theNumFields, index; + NSUInteger index; MYSQL_FIELD *theField; if (mResult == NULL) { @@ -878,7 +878,6 @@ const OUR_CHARSET our_charsets60[] = [self fetchFieldNames]; } - theNumFields = [self numOfFields]; theField = mysql_fetch_fields(mResult); if ([mNames indexOfObject:key] == NSNotFound) { @@ -952,7 +951,7 @@ const OUR_CHARSET our_charsets60[] = - (BOOL)isBlobForKey:(NSString *)key { BOOL theRet; - NSUInteger theNumFields, index; + NSUInteger index; MYSQL_FIELD *theField; if (mResult == NULL) { @@ -964,7 +963,6 @@ const OUR_CHARSET our_charsets60[] = [self fetchFieldNames]; } - theNumFields = [self numOfFields]; theField = mysql_fetch_fields(mResult); if ([mNames indexOfObject:key] == NSNotFound) { -- cgit v1.2.3