Permalink
Browse files

Fix a warning on 10.6 about memory leaks

  • Loading branch information...
dmoagx committed May 18, 2018
1 parent f20ab36 commit 38b9659bc740bf1b5b63d8a84f5633fa593e77b4
Showing with 33 additions and 31 deletions.
  1. +33 −31 Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m
@@ -87,43 +87,45 @@ - (void)_keepAlive
*/
- (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;
}
}
}

0 comments on commit 38b9659

Please sign in to comment.