View Issue Details

IDProjectCategoryView StatusLast Update
0037228FPCCompilerpublic2020-06-21 17:11
Reporterrunewalsh Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037228: dispose() computes its argument twice
DescriptionIt looks like when dispose()'ing managed type, such as AnsiString, dispose(), not being a real function, splits itself into Finalize() and FreeMem(), and computes its argument twice regardless of side effects.
Steps To Reproduce{$mode objfpc} {$h+}
function CreateString: pString;
begin
    writeln('Creating a string');
    new(result);
end;

begin
    dispose(CreateString); // prints “Creating a string” twice
end.
Additional InformationIn accordance with my hypothesis, this bug does not manifests itself with unmanaged types.
TagsNo tags attached.
Fixed in Revision45673
FPCOldBugId
FPCTarget-
Attached Files

Activities

runewalsh

2020-06-20 18:21

reporter   ~0123485

*does not manifesT D:

Serge Anvarov

2020-06-20 20:21

reporter   ~0123489

This is not related to the new features of FPC, because it is reproduced in version 3.0.4. Additionally, there is a memory leak (twice new).

runewalsh

2020-06-20 20:56

reporter   ~0123490

Last edited: 2020-06-20 21:15

View 3 revisions

Ew, sorry, I wasn't familiar with all those bugtracker conventions D:

Well, I didn't found that because I could never think out a realistic scenario with new(DirtyFunction()), while dispose(DirtyFunction()) easily pops out (pun intended) when working with collections of user-owned new'ed pointers with the capability of destructive iteration (like dict/list.pop() in Python): destroying such collection and its elements can look precisely like

while not collection.Empty do
    dispose(collection.Pop);
collection.Free;

P.S. After 5 minutes I realized that I misunderstood you, but I'll leave this note to posterity, as it mentions a realistic use case :|

Issue History

Date Modified Username Field Change
2020-06-20 17:55 runewalsh New Issue
2020-06-20 18:21 runewalsh Note Added: 0123485
2020-06-20 20:21 Serge Anvarov Note Added: 0123489
2020-06-20 20:56 runewalsh Note Added: 0123490
2020-06-20 21:15 runewalsh Note Edited: 0123490 View Revisions
2020-06-20 21:15 runewalsh Note Edited: 0123490 View Revisions
2020-06-21 17:11 Jonas Maebe Assigned To => Jonas Maebe
2020-06-21 17:11 Jonas Maebe Status new => resolved
2020-06-21 17:11 Jonas Maebe Resolution open => fixed
2020-06-21 17:11 Jonas Maebe Fixed in Version => 3.3.1
2020-06-21 17:11 Jonas Maebe Fixed in Revision => 45673
2020-06-21 17:11 Jonas Maebe FPCTarget => -