Skip to content

Commit 3fb5b84

Browse files
authored
Merge pull request #122 from jkour/Pool-AV
[pool] An AV occurs in TPoolItem
2 parents 92e8f5d + 815fe83 commit 3fb5b84

File tree

2 files changed

+410
-266
lines changed

2 files changed

+410
-266
lines changed

Quick.Pooling.pas

+4-4
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,22 @@ function TPoolItem<T>._AddRef: Integer;
295295

296296
function TPoolItem<T>._Release: Integer;
297297
begin
298-
fLock.Enter;
299298
{$IFDEF DEBUG_OBJPOOL}
300299
TDebugger.Trace(Self,'Released Pool item');
301300
{$ENDIF}
302301
try
303-
Dec(fRefCount);
304-
Result := fRefCount;
302+
result:=AtomicDecrement(fRefCount);
305303
if Result = 0 then
306304
begin
307305
FreeAndNil(fItem);
306+
// The following is take from TInterfacedObject._Release()
307+
// Mark the refcount field so that any refcounting during destruction doesn't infinitely recurse.
308+
__MarkDestroying(Self);
308309
Destroy;
309310
end
310311
else fLastAccess := Now;
311312
finally
312313
if fRefCount = 1 then fSemaphore.Release;
313-
fLock.Leave;
314314
end;
315315
end;
316316

0 commit comments

Comments
 (0)