From ddc0ac9a43e5e7911a857e47f15c3fcec7e9aad5 Mon Sep 17 00:00:00 2001 From: tom_at_work Date: Tue, 11 Sep 2007 22:23:33 +0000 Subject: [PATCH] * better fix for TFPGSList memory leak: avoid changing allocation behavior (adds one temp entry used for various operations), and clean up in the destructor git-svn-id: trunk@8433 - --- rtl/objpas/fgl.pp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rtl/objpas/fgl.pp b/rtl/objpas/fgl.pp index c6fd890279..d11f7ca797 100644 --- a/rtl/objpas/fgl.pp +++ b/rtl/objpas/fgl.pp @@ -215,6 +215,9 @@ end; destructor TFPSList.Destroy; begin Clear; + // Clear() does not clear the whole list; there is always a single temp entry + // at the end which is never freed. Take care of that one here. + FreeMem(FList); inherited Destroy; end; @@ -261,8 +264,8 @@ begin Error(SListCapacityError, NewCapacity); if NewCapacity = FCapacity then exit; - ReallocMem(FList, NewCapacity * FItemSize); - FillChar(InternalItems[FCapacity]^, (NewCapacity-FCapacity) * FItemSize, #0); + ReallocMem(FList, (NewCapacity+1) * FItemSize); + FillChar(InternalItems[FCapacity]^, (NewCapacity+1-FCapacity) * FItemSize, #0); FCapacity := NewCapacity; end; @@ -315,7 +318,6 @@ begin begin SetCount(0); SetCapacity(0); - FList := nil; end; end;