From 38b9659bc740bf1b5b63d8a84f5633fa593e77b4 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 19 May 2018 01:27:49 +0200 Subject: Fix a warning on 10.6 about memory leaks --- .../Ping & KeepAlive.m | 64 +++++++++++----------- 1 file changed, 33 insertions(+), 31 deletions(-) (limited to 'Frameworks/SPMySQLFramework') diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m index d1de87a1..09988dbe 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m @@ -87,43 +87,45 @@ typedef struct { */ - (void)_threadedKeepAlive { - @synchronized(self) { - if(keepAliveThread) { - NSLog(@"warning: overwriting existing keepAliveThread: %@, results may be unpredictable!",keepAliveThread); + @autoreleasepool { + @synchronized(self) { + if(keepAliveThread) { + NSLog(@"warning: overwriting existing keepAliveThread: %@, results may be unpredictable!",keepAliveThread); + } + keepAliveThread = [NSThread currentThread]; } - keepAliveThread = [NSThread currentThread]; - } - - [keepAliveThread setName:[NSString stringWithFormat:@"SPMySQL connection keepalive monitor thread (id=%p)", self]]; - // If the maximum number of ping failures has been reached, determine whether to reconnect. - if (keepAliveLastPingBlocked || keepAlivePingFailures >= 3) { + [keepAliveThread setName:[NSString stringWithFormat:@"SPMySQL connection keepalive monitor thread (id=%p)", self]]; - // If the connection has been used within the last fifteen minutes, - // attempt a single reconnection in the background - if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 60 * 15) { - [self _reconnectAfterBackgroundConnectionLoss]; - } - // Otherwise set the state to connection lost for automatic reconnect on - // next use. - else { - state = SPMySQLConnectionLostInBackground; - } + // If the maximum number of ping failures has been reached, determine whether to reconnect. + if (keepAliveLastPingBlocked || keepAlivePingFailures >= 3) { - // Return as no further ping action required this cycle. - goto end_cleanup; - } + // If the connection has been used within the last fifteen minutes, + // attempt a single reconnection in the background + if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 60 * 15) { + [self _reconnectAfterBackgroundConnectionLoss]; + } + // Otherwise set the state to connection lost for automatic reconnect on + // next use. + else { + state = SPMySQLConnectionLostInBackground; + } - // Otherwise, perform a background ping. - BOOL pingResult = [self _pingConnectionUsingLoopDelay:10000]; - if (pingResult) { - keepAlivePingFailures = 0; - } else { - keepAlivePingFailures++; - } + // Return as no further ping action required this cycle. + goto end_cleanup; + } + + // Otherwise, perform a background ping. + BOOL pingResult = [self _pingConnectionUsingLoopDelay:10000]; + if (pingResult) { + keepAlivePingFailures = 0; + } else { + keepAlivePingFailures++; + } end_cleanup: - @synchronized(self) { - keepAliveThread = nil; + @synchronized(self) { + keepAliveThread = nil; + } } } -- cgit v1.2.3