Another fix for modern runtimes not handling resurrection of objects

This commit is contained in:
rfm 2025-01-02 16:28:55 +00:00
parent 1ec70f9323
commit 9f90bdc755

View file

@ -2578,14 +2578,21 @@ static int poolConnections = 0;
* from grabbing this object while we are checking it. * from grabbing this object while we are checking it.
*/ */
[clientsLock lock]; [clientsLock lock];
if (nil != _pool && [self retainCount] == 1) if ([self retainCount] > 1)
{
[super release];
[clientsLock unlock];
return;
}
if (_pool)
{ {
/* This is the only reference to a client associated with /* This is the only reference to a client associated with
* a connection pool we put this client back to the pool. * a connection pool we put this client back to the pool.
* *
* That being the case, we know that this thread 'owns' * That being the case, we know that this thread 'owns'
* the client and it's not going to be deallocated and not * the client and it's not going to be deallocated and not
* going to have the _pool iinstance variable changed, so it * going to have the _pool instance variable changed, so it
* is safe to unlock clientsLock before returning the client * is safe to unlock clientsLock before returning the client
* to the pool. This avoids a possible deadlock when a pool * to the pool. This avoids a possible deadlock when a pool
* is being purged. * is being purged.
@ -2602,12 +2609,10 @@ static int poolConnections = 0;
} }
else else
{ {
/* If we are going to deallocate the object, we first remove /* As we are going to deallocate the object, we first remove
* it from global tables so that no other thread will find it * it from global tables so that no other thread will find it
* and try to use it while it is being deallocated. * and try to use it while it is being deallocated.
*/ */
if (NSDecrementExtraRefCountWasZero(self))
{
NSHashRemove(clientsHash, (void*)self); NSHashRemove(clientsHash, (void*)self);
if (_name != nil if (_name != nil
&& (SQLClient*)NSMapGet(clientsMap, (void*)_name) == self) && (SQLClient*)NSMapGet(clientsMap, (void*)_name) == self)
@ -2615,12 +2620,7 @@ static int poolConnections = 0;
NSMapRemove(clientsMap, (void*)_name); NSMapRemove(clientsMap, (void*)_name);
} }
[clientsLock unlock]; [clientsLock unlock];
[self dealloc]; [super release];
}
else
{
[clientsLock unlock];
}
} }
} }