aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-05-13 17:57:10 +0000
committerrowanbeentje <rowan@beent.je>2012-05-13 17:57:10 +0000
commita181f7f7ea4548bf2a41a97b814e9cd8f45b2b08 (patch)
tree74c2d1be3beefb114554e700dac80ecdc70c6f4b
parenta0dd563f044459fa497794bbcd5041fa8e47f613 (diff)
downloadsequelpro-a181f7f7ea4548bf2a41a97b814e9cd8f45b2b08.tar.gz
sequelpro-a181f7f7ea4548bf2a41a97b814e9cd8f45b2b08.tar.bz2
sequelpro-a181f7f7ea4548bf2a41a97b814e9cd8f45b2b08.zip
- Manually allocate memory for table selection restoration processing instead of relying on the stack; this should address exceptions on background threads when loading tables
-rw-r--r--Source/SPTableContent.m10
1 files 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