From 64307838194fd153b88df82156a7fad3ff68de4c Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Wed, 26 May 2010 12:49:18 +0000 Subject: Fix an overreleased dictionary crash and always ensure both autorelease pools are released to prevent potential memory leaks. Fixes log http://spbug.com/l/584. --- Source/SPCSVExporter.m | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Source') diff --git a/Source/SPCSVExporter.m b/Source/SPCSVExporter.m index e6342e68..fe6ebdac 100644 --- a/Source/SPCSVExporter.m +++ b/Source/SPCSVExporter.m @@ -179,7 +179,7 @@ if ([self csvTableName] && (![self csvDataArray])) { - NSDictionary *tableDetails = [[NSDictionary alloc] init]; + NSDictionary *tableDetails; // Determine whether the supplied table is actually a table or a view via the CREATE TABLE command, and get the table details MCPResult *queryResult = [connection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE %@", [[self csvTableName] backtickQuotedString]]]; @@ -187,9 +187,9 @@ [queryResult setReturnDataAsStrings:YES]; if ([queryResult numOfRows]) { - tableDetails = [NSDictionary dictionaryWithDictionary:[queryResult fetchRowAsDictionary]]; + tableDetails = [[NSDictionary alloc] initWithDictionary:[queryResult fetchRowAsDictionary]]; - tableDetails = [NSDictionary dictionaryWithDictionary:([tableDetails objectForKey:@"Create View"]) ? [[self csvTableData] informationForView:[self csvTableName]] : [[self csvTableData] informationForTable:[self csvTableName]]]; + tableDetails = [[NSDictionary alloc] initWithDictionary:([tableDetails objectForKey:@"Create View"]) ? [[self csvTableData] informationForView:[self csvTableName]] : [[self csvTableData] informationForTable:[self csvTableName]]]; } // Retrieve the table details via the data class, and use it to build an array containing column numeric status @@ -316,7 +316,7 @@ ([csvCellString length] > 1 && [csvCellString characterAtIndex:1] == '.')); } - + // Escape any occurrences of the escaping character [csvCellString replaceOccurrencesOfString:[self csvEscapeString] withString:escapedEscapeString @@ -381,14 +381,14 @@ // Inform the delegate that the export's progress has been updated [delegate performSelectorOnMainThread:@selector(csvExportProcessProgressUpdated:) withObject:self waitUntilDone:NO]; - // If an array was supplied and we've processed all rows, break - if ([self csvDataArray] && (totalRows == currentRowIndex)) break; - // Drain the autorelease pool as required to keep memory usage low if (currentPoolDataLength > 250000) { [csvExportPool release]; csvExportPool = [[NSAutoreleasePool alloc] init]; } + + // If an array was supplied and we've processed all rows, break + if ([self csvDataArray] && (totalRows == currentRowIndex)) break; } // Write data to disk @@ -400,6 +400,7 @@ // Inform the delegate that the export process is complete [delegate performSelectorOnMainThread:@selector(csvExportProcessComplete:) withObject:self waitUntilDone:NO]; + [csvExportPool release]; [pool release]; } @catch(NSException *e) {} -- cgit v1.2.3