[fpc-pascal] TList.SetCount patch

Joao Morais post at joaomorais.com.br
Fri May 23 02:06:50 CEST 2008


Hello,

the following patch fixes a memory leakage for lists with owned objects. =

(patch against fixes_2_2, sorry, at least it is an one file patch and =

very small)

Joao Morais

-------------- next part --------------
Index: rtl/objpas/classes/lists.inc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- rtl/objpas/classes/lists.inc	(revision 11044)
+++ rtl/objpas/classes/lists.inc	(working copy)
@@ -546,7 +546,11 @@
 =

 procedure TList.SetCount(NewCount: Integer);
 begin
-  FList.SetCount(NewCount);
+  if NewCount < FList.Count then
+    while FList.Count > NewCount do
+      Delete(FList.Count - 1)
+  else
+    FList.SetCount(NewCount);
 end;
 =

 constructor TList.Create;


More information about the fpc-pascal mailing list