Recent

Author Topic: [SOLVED] Problem with HeapTrc  (Read 224 times)

Phoenix

  • Jr. Member
  • **
  • Posts: 61
[SOLVED] Problem with HeapTrc
« on: July 13, 2019, 03:05:12 pm »
Hello,
I detected a problem and tried to isolate it in a minimal test application.
Always reproducible error (computer restarted for clean memory)

Configuration:
Windows 10 64bit
Lazarus 2.0.2 FPC 3.0.4 64bit

The problem only occurs if the following option is active:
Project options -> Debugging -> "Use Heaptrc unit (check for mem-leaks) (-gh)"

I attach the source for the test and the images of the error.

I could use the alternative commented code but the other one seems correct to me.


Any help is welcome  :'(
« Last Edit: July 13, 2019, 04:45:22 pm by Phoenix »

ASerge

  • Hero Member
  • *****
  • Posts: 1412
Re: Problem with HeapTrc
« Reply #1 on: July 13, 2019, 04:30:42 pm »
I could use the alternative commented code but the other one seems correct to me.
Code error. SizeOf(ARows) = SizeOf(Pointer). Judging by the screenshot, it is a 64-bit program, i.e. it is 8 bytes. But the length of the ARows is only 1 byte.

totya

  • Hero Member
  • *****
  • Posts: 577
Re: Problem with HeapTrc
« Reply #2 on: July 13, 2019, 04:31:50 pm »
Your code:
Code: Pascal  [Select]
  1. procedure TEST_ERROR;
  2. Var
  3.  //i: Integer;
  4.  
  5.  ARows: array of Byte;
  6. begin
  7.  SetLength(ARows,1);
  8.  try
  9.   FillChar(ARows[0],SizeOf(ARows),0);
  10.  
  11.   //for i:= Low(ARows) to High(ARows) do
  12.   // ARows[i]:= 0;
  13.  finally
  14.   SetLength(ARows,0);
  15.  end;
  16. end;

See it:

Code: Pascal  [Select]
  1. FillChar(ARows[0], SizeOf(ARows[0]) * Length(ARows), 0);

Phoenix

  • Jr. Member
  • **
  • Posts: 61
Re: [SOLVED] Problem with HeapTrc
« Reply #3 on: July 13, 2019, 04:44:10 pm »
Thanks, in fact, really a big mistake.  :-[

totya

  • Hero Member
  • *****
  • Posts: 577
Re: [SOLVED] Problem with HeapTrc
« Reply #4 on: July 13, 2019, 04:48:41 pm »
Thanks, in fact, really a big mistake.  :-[

If you use non-stardand variable operations, I mean when you use direct memory access, then you must be careful.