diff options
author | rowanbeentje <rowan@beent.je> | 2010-03-15 00:15:23 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-03-15 00:15:23 +0000 |
commit | 5a6d0f17bbf6b09463b908182dc2cbb112a0c6cb (patch) | |
tree | 4eb9575d7de321fc6f454892d0df13ddc4b6ce39 /Source/SPTableData.m | |
parent | 927784129ffd4d30e35f92a3fe6a8582219c64db (diff) | |
download | sequelpro-5a6d0f17bbf6b09463b908182dc2cbb112a0c6cb.tar.gz sequelpro-5a6d0f17bbf6b09463b908182dc2cbb112a0c6cb.tar.bz2 sequelpro-5a6d0f17bbf6b09463b908182dc2cbb112a0c6cb.zip |
Following a manual code review, fix some local variables overriding global variables, a few leaks, and additional nil setting/checking to prevent overreleases or releases of random areas of memory.
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r-- | Source/SPTableData.m | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m index 20a3dbd7..459406fc 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -313,9 +313,9 @@ - (NSDictionary *) informationForTable:(NSString *)tableName { SPSQLParser *createTableParser, *fieldsParser, *fieldParser; - NSMutableArray *tableColumns, *fieldStrings, *definitionParts; + NSMutableArray *tableColumns, *fieldStrings; NSMutableDictionary *tableColumn, *tableData; - NSString *encodingString; + NSString *encodingString = nil; NSUInteger i, stringStart; unichar quoteCharacter; @@ -366,7 +366,6 @@ // table information. Proceed further by parsing the field strings. tableColumns = [[NSMutableArray alloc] init]; tableColumn = [[NSMutableDictionary alloc] init]; - definitionParts = [[NSMutableArray alloc] init]; fieldParser = [[SPSQLParser alloc] init]; NSCharacterSet *whitespaceAndNewlineSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; @@ -384,7 +383,6 @@ continue; } [tableColumn removeAllObjects]; - [definitionParts removeAllObjects]; // If the first character is a quote character, this is a field definition. if ([quoteSet characterIsMember:[fieldsParser characterAtIndex:0]]) { @@ -535,9 +533,9 @@ if([parsedString length]>4) { NSString *priFieldName = [[parsedString substringWithRange:NSMakeRange(2,[parsedString length]-4)] stringByReplacingOccurrencesOfString:@"``" withString:@"`"]; [tableData setObject:priFieldName forKey:@"primarykeyfield"]; - for(id tableColumn in tableColumns) - if([[tableColumn objectForKey:@"name"] isEqualToString:priFieldName]) { - [tableColumn setObject:[NSNumber numberWithInteger:1] forKey:@"isprimarykey"]; + for(id theTableColumn in tableColumns) + if([[theTableColumn objectForKey:@"name"] isEqualToString:priFieldName]) { + [theTableColumn setObject:[NSNumber numberWithInteger:1] forKey:@"isprimarykey"]; break; } } @@ -550,9 +548,9 @@ NSArray *uniqueFieldNames = [parsedString componentsSeparatedByString:@"`,`"]; for(NSString* uniq in uniqueFieldNames) { NSString *uniqField = [[uniq stringByReplacingOccurrencesOfRegex:@"^\\(`|`\\)" withString:@""] stringByReplacingOccurrencesOfString:@"``" withString:@"`"]; - for(id tableColumn in tableColumns) - if([[tableColumn objectForKey:@"name"] isEqualToString:uniqField]) { - [tableColumn setObject:[NSNumber numberWithInteger:1] forKey:@"unique"]; + for(id theTableColumn in tableColumns) + if([[theTableColumn objectForKey:@"name"] isEqualToString:uniqField]) { + [theTableColumn setObject:[NSNumber numberWithInteger:1] forKey:@"unique"]; break; } } @@ -567,7 +565,6 @@ } [fieldStrings release]; [fieldsParser release]; - [definitionParts release]; [tableColumn release]; // Extract the encoding from the table properties string - other details come from TABLE STATUS. @@ -610,7 +607,7 @@ tableName, [mySQLConnection getLastErrorMessage]]); } [tableColumns release]; - [encodingString release]; + if (encodingString) [encodingString release]; return nil; } @@ -707,6 +704,7 @@ } // Retrieve the table syntax string + if (tableCreateSyntax) [tableCreateSyntax release], tableCreateSyntax = nil; tableCreateSyntax = [[NSString alloc] initWithString:[[theResult fetchRowAsArray] objectAtIndex:1]]; // Retrieve the SHOW COLUMNS syntax for the table |