View Issue Details

IDProjectCategoryView StatusLast Update
0021529FPCRTLpublic2012-03-26 02:03
ReporterLuiz Americo Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Target Version3.0.0Fixed in Version2.6.1 
Summary0021529: Do not call Clear in TStringList.Destroy
DescriptionIn revision 20265 a call to Clear was added to TStringList.Destroy

I tested in Delphi and is Clear is not called after calling Destroy.

Furthermore this is leading to crashes in third party components (zeos)

Attached a patch, a demo, and a test suited to fpc test suite
TagsNo tags attached.
Fixed in Revision20582
FPCOldBugId0
FPCTarget
Attached Files

Relationships

related to 0021433 closedJonas Maebe Strange behavior Lazarus on the latest revisions FPC 

Activities

2012-03-22 12:17

 

slist_clear.diff (1,967 bytes)   
Index: rtl/objpas/classes/classesh.inc
===================================================================
--- rtl/objpas/classes/classesh.inc	(revision 20547)
+++ rtl/objpas/classes/classesh.inc	(working copy)
@@ -679,6 +679,7 @@
     FOwnsObjects : Boolean;
     procedure ExchangeItems(Index1, Index2: Integer);
     procedure Grow;
+    procedure InternalClear;
     procedure QuickSort(L, R: Integer; CompareFn: TStringListSortCompare);
     procedure SetSorted(Value: Boolean);
     procedure SetCaseSensitive(b : boolean);
Index: rtl/objpas/classes/stringl.inc
===================================================================
--- rtl/objpas/classes/stringl.inc	(revision 20547)
+++ rtl/objpas/classes/stringl.inc	(working copy)
@@ -908,7 +908,28 @@
   SetCapacity(NC);
 end;
 
+Procedure TStringList.InternalClear;
+
+Var
+  I: Integer;
 
+begin
+  if FOwnsObjects then
+    begin
+      For I:=0 to FCount-1 do
+        begin
+          Flist^[I].FString:='';
+          freeandnil(Flist^[i].FObject);
+        end;
+    end
+  else
+    begin
+      For I:=0 to FCount-1 do
+        Flist^[I].FString:='';
+    end;
+  FCount:=0;
+  SetCapacity(0);
+end;
 
 Procedure TStringList.QuickSort(L, R: Integer; CompareFn: TStringListSortCompare);
 var
@@ -1128,13 +1149,8 @@
 
 destructor TStringList.Destroy;
 
-Var I : Longint;
-
 begin
-  FOnChange:=Nil;
-  FOnChanging:=Nil;
-  Clear;
-  SetCapacity(0);
+  InternalClear;
   Inherited destroy;
 end;
 
@@ -1156,26 +1172,10 @@
 
 Procedure TStringList.Clear;
 
-Var I : longint;
-
 begin
   if FCount = 0 then Exit;
   Changing;
-  if FOwnsObjects then
-    begin
-      For I:=0 to FCount-1 do
-        begin
-          Flist^[I].FString:='';
-          freeandnil(Flist^[i].FObject);
-        end;
-    end
-  else
-    begin
-      For I:=0 to FCount-1 do
-        Flist^[I].FString:='';
-    end;
-  FCount:=0;
-  SetCapacity(0);
+  InternalClear;
   Changed;
 end;
 
slist_clear.diff (1,967 bytes)   

2012-03-22 12:18

 

2012-03-22 12:18

 

Marcos Douglas

2012-03-22 12:46

reporter   ~0057915

I confirm that.

Michael Van Canneyt

2012-03-22 13:10

administrator   ~0057916

Applied the patch, thank you.

Luiz Americo

2012-03-22 15:26

developer   ~0057920

Thanks

Can you merge to 2.6 fixes branch? (The offending revision was merged to 2.6 fixes)

Marco van de Voort

2012-03-22 21:12

manager   ~0057930

I'm sure that can be arranged.

Issue History

Date Modified Username Field Change
2012-03-22 12:17 Luiz Americo New Issue
2012-03-22 12:17 Luiz Americo File Added: slist_clear.diff
2012-03-22 12:17 Luiz Americo FPCOldBugId => 0
2012-03-22 12:18 Luiz Americo File Added: bugStringListDestroy.lpr
2012-03-22 12:18 Luiz Americo File Added: bugStringListDestroy_fpctest.lpr
2012-03-22 12:44 Jonas Maebe Status new => assigned
2012-03-22 12:44 Jonas Maebe Assigned To => Michael Van Canneyt
2012-03-22 12:46 Marcos Douglas Note Added: 0057915
2012-03-22 13:10 Michael Van Canneyt Fixed in Revision => 20570
2012-03-22 13:10 Michael Van Canneyt Status assigned => resolved
2012-03-22 13:10 Michael Van Canneyt Fixed in Version => 2.7.1
2012-03-22 13:10 Michael Van Canneyt Resolution open => fixed
2012-03-22 13:10 Michael Van Canneyt Note Added: 0057916
2012-03-22 13:10 Michael Van Canneyt Target Version => 3.0.0
2012-03-22 13:31 Jonas Maebe Relationship added related to 0021433
2012-03-22 15:26 Luiz Americo Status resolved => feedback
2012-03-22 15:26 Luiz Americo Resolution fixed => reopened
2012-03-22 15:26 Luiz Americo Note Added: 0057920
2012-03-22 21:12 Marco van de Voort Status feedback => resolved
2012-03-22 21:12 Marco van de Voort Resolution reopened => fixed
2012-03-22 21:12 Marco van de Voort Note Added: 0057930
2012-03-25 19:00 Jonas Maebe Fixed in Revision 20570 => 20582
2012-03-25 19:00 Jonas Maebe Fixed in Version 2.7.1 => 2.6.1
2012-03-26 02:03 Luiz Americo Status resolved => closed