Memory leak copying dynamic arrays.
Original Reporter info from Mantis: bruce
-
Reporter name: Bruce Tulloch
Original Reporter info from Mantis: bruce
- Reporter name: Bruce Tulloch
Description:
When the result of Copy() is used as an argument to another Copy() and the program is compiled -MDelphi reference counting for (copied) dynamic arrays is broken such that the arrays are never returned to the heap.
Steps to reproduce:
Compile this program (copytest.pas):
program copytest;
var
S, D : array of Integer;
begin
SetLength(S,4000);
D := Copy(Copy(S));
end.
using this command line:
fpc -MDelphi -gl -gh copytest.pas
and run it. It produces a result like this:
lenin:$ ./copytest
Heap dump by heaptrc unit
3 memory blocks allocated : 48024/48024
2 memory blocks freed : 32016/32016
1 unfreed memory blocks : 16008
True heap size : 262144
True free heap : 246048
Should be : 246072
Call trace for block $B7F4BF50 size 16008
$080480EA main, line 8 of copytest.pas
$080657A7
Additional information:
If compiled without -MDelphi it works
lenin:$ ./copytest
Heap dump by heaptrc unit
3 memory blocks allocated : 24024/24024
3 memory blocks freed : 24024/24024
0 unfreed memory blocks : 0
True heap size : 262144
True free heap : 262144
so it's something to do with -MDelphi.
Mantis conversion info:
- Mantis ID: 13820
- OS: Debian
- OS Build: Lenny
- Build: r13188
- Platform: Linux
- Version: 2.3.1
- Fixed in version: 2.4.0
- Fixed in revision: 13195 (#966ebbf1)