From f6de38fa5cc34461513670e52d5a9801ff8d8b32 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 18 Mar 2012 00:51:52 +0000 Subject: - Fix crashes caused by the database structure retrieval continuing briefly after the parent document was closed --- Source/SPDatabaseDocument.m | 1 + Source/SPDatabaseStructure.h | 3 ++- Source/SPDatabaseStructure.m | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'Source') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index cff43d9b..7fd93c1b 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -5647,6 +5647,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif + [databaseStructureRetrieval destroy]; [databaseStructureRetrieval release]; [allDatabases release]; diff --git a/Source/SPDatabaseStructure.h b/Source/SPDatabaseStructure.h index 2b2d6977..52e43ec8 100644 --- a/Source/SPDatabaseStructure.h +++ b/Source/SPDatabaseStructure.h @@ -39,9 +39,10 @@ pthread_mutex_t connectionCheckLock; } -// Setup +// Setup and teardown - (id)initWithDelegate:(SPDatabaseDocument *)theDelegate; - (void)setConnectionToClone:(SPMySQLConnection *)aConnection; +- (void)destroy; // Information - (SPMySQLConnection *)connection; diff --git a/Source/SPDatabaseStructure.m b/Source/SPDatabaseStructure.m index 42896b55..3579e269 100644 --- a/Source/SPDatabaseStructure.m +++ b/Source/SPDatabaseStructure.m @@ -95,8 +95,12 @@ [NSThread detachNewThreadSelector:@selector(_cloneConnectionFromConnection:) toTarget:self withObject:aConnection]; } -- (void)dealloc +/** + * Ensure that processing is completed. + */ +- (void)destroy { + delegate = nil; // Ensure all the retrieval threads have ended pthread_mutex_lock(&threadManagementLock); @@ -111,12 +115,17 @@ } } pthread_mutex_unlock(&threadManagementLock); + +} + +- (void)dealloc +{ + [self destroy]; [structureRetrievalThreads release]; pthread_mutex_destroy(&threadManagementLock); pthread_mutex_destroy(&dataLock); pthread_mutex_destroy(&connectionCheckLock); - delegate = nil; if (mySQLConnection) [mySQLConnection release], mySQLConnection = nil; if (structure) [structure release], structure = nil; @@ -619,7 +628,7 @@ - (BOOL)_ensureConnection { - if (!mySQLConnection) return NO; + if (!mySQLConnection || !delegate) return NO; // Check the connection state if ([mySQLConnection isConnected] && [mySQLConnection checkConnection]) return YES; -- cgit v1.2.3