Explorar el Código

Fix an AV in pool item

jkour hace 1 año
padre
commit
815fe83e72
Se han modificado 1 ficheros con 4 adiciones y 4 borrados
  1. 4 4
      Quick.Pooling.pas

+ 4 - 4
Quick.Pooling.pas

@@ -295,22 +295,22 @@ end;
 
 function TPoolItem<T>._Release: Integer;
 begin
-  fLock.Enter;
   {$IFDEF DEBUG_OBJPOOL}
   TDebugger.Trace(Self,'Released Pool item');
   {$ENDIF}
   try
-    Dec(fRefCount);
-    Result := fRefCount;
+    result:=AtomicDecrement(fRefCount);
     if Result = 0 then
     begin
       FreeAndNil(fItem);
+      // The following is take from TInterfacedObject._Release()
+      // Mark the refcount field so that any refcounting during destruction doesn't infinitely recurse.
+      __MarkDestroying(Self);
       Destroy;
     end
     else fLastAccess := Now;
   finally
     if fRefCount = 1 then fSemaphore.Release;
-    fLock.Leave;
   end;
 end;