From a181f7f7ea4548bf2a41a97b814e9cd8f45b2b08 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 13 May 2012 17:57:10 +0000 Subject: - Manually allocate memory for table selection restoration processing instead of relying on the stack; this should address exceptions on background threads when loading tables --- Source/SPTableContent.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 9036c393..ade6dd5a 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -861,7 +861,7 @@ BOOL columnsFound = YES; NSArray *primaryKeyFieldNames = [selectionToRestore objectForKey:@"keys"]; NSUInteger primaryKeyFieldCount = [primaryKeyFieldNames count]; - NSUInteger primaryKeyFieldIndexes[primaryKeyFieldCount]; + NSUInteger *primaryKeyFieldIndexes = malloc(primaryKeyFieldCount * sizeof(NSUInteger)); for (NSUInteger i = 0; i < primaryKeyFieldCount; i++) { primaryKeyFieldIndexes[i] = [[tableDataInstance columnNames] indexOfObject:[primaryKeyFieldNames objectAtIndex:i]]; if (primaryKeyFieldIndexes[i] == NSNotFound) { @@ -870,7 +870,7 @@ } // Only proceed with reselection if all columns were found - if (columnsFound) { + if (columnsFound && primaryKeyFieldCount) { NSDictionary *selectionKeysToRestore = [selectionToRestore objectForKey:@"rows"]; NSUInteger rowsToSelect = [selectionKeysToRestore count]; BOOL rowMatches = NO; @@ -903,6 +903,8 @@ } } + free(primaryKeyFieldIndexes); + } else if ([[selectionToRestore objectForKey:@"type"] isEqualToString:SPSelectionDetailTypeIndexed]) { selectionSet = [selectionToRestore objectForKey:@"rows"]; } @@ -3710,7 +3712,7 @@ // Set up an array of the column indexes to store NSUInteger primaryKeyFieldCount = [primaryKeyFieldNames count]; - NSUInteger primaryKeyFieldIndexes[primaryKeyFieldCount]; + NSUInteger *primaryKeyFieldIndexes = malloc(sizeof(NSUInteger) * primaryKeyFieldCount); BOOL problemColumns = NO; for (NSUInteger i = 0; i < primaryKeyFieldCount; i++) { primaryKeyFieldIndexes[i] = [[tableDataInstance columnNames] indexOfObject:[primaryKeyFieldNames objectAtIndex:i]]; @@ -3752,6 +3754,7 @@ } } free(indexBuffer); + free(primaryKeyFieldIndexes); return [NSDictionary dictionaryWithObjectsAndKeys: SPSelectionDetailTypePrimaryKeyed, @"type", @@ -3759,6 +3762,7 @@ primaryKeyFieldNames, @"keys", nil]; } + free(primaryKeyFieldIndexes); } // If no primary key was available, fall back to using just the selected row indexes if permitted -- cgit v1.2.3