Re: [Lazarus] Memory corruption investigation

2012-03-22 Thread Felipe Monteiro de Carvalho
On Thu, Mar 22, 2012 at 1:13 AM, Mattias Gaertner
nc-gaert...@netcologne.de wrote:
 Have you tried the keepreleased?

I set it to true as the first item in my program code and also in an
offending unit but couldnt see much of a difference.

I suppose that I should look for which block contains $B73DE820 to see
who allocated the memory, but there are no blocks in the listing:

Marked memory at $B73DE820 invalid
Wrong signature $ instead of 755D2E31
  $08065DEB
  $08065EA7
  $0805C898
  $0812AAEC  TLAZINTFIMAGE__DESTROY,  line 3244 of intfgraphics.pas
  $08057AE2
  $08057AE2
  $0817E53E  TCDWIDGETSET__DELETEOBJECT,  line 863 of
./customdrawn/customdrawnwinapi.inc
  $0816DF2F  DELETEOBJECT,  line 181 of ./include/winapi.inc
  $080FDC2E  TSHAREDRASTERIMAGE__FREEHANDLE,  line 40 of
./include/sharedrasterimage.inc
Heap dump by heaptrc unit
432 memory blocks allocated : 101773/102496
378 memory blocks freed : 92141/92816
54 unfreed memory blocks : 9632
True heap size : 786432
True free heap : 769024
Should be : 773296
Call trace for block $B73DD9C0 size 2160
  $0805C898
  $080DA2C7  TRAWIMAGE__EXTRACTRECT,  line 1576 of graphtype.pp
  $08100EF3  TCUSTOMBITMAP__SETSIZE,  line 342 of ./include/custombitmap.inc
  $08100360  TRASTERIMAGE__SETWIDTH,  line 956 of ./include/rasterimage.inc
  $08080925  TCDDRAWER__SCALERASTERIMAGE,  line 561 of customdrawndrawers.pas
  $08082120  TCDDRAWERANDROID__LOADRESOURCES,  line 482 of
customdrawn_android.pas
  $08080666  TCDDRAWER__CREATE,  line 518 of customdrawndrawers.pas
  $08083265  CUSTOMDRAWN_ANDROID_init,  line 759 of customdrawn_android.pas
// 

The closest one is this first block, but still B73DD9C0 + 2160 is
B73DE230 which is less then B73DE820

-- 
Felipe Monteiro de Carvalho

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Memory corruption investigation

2012-03-22 Thread Felipe Monteiro de Carvalho
Ok, now I found who is causing the problem =)

function TCDWidgetSet.RawImage_CreateBitmaps(const ARawImage:
TRawImage; out ABitmap, AMask: HBitmap; ASkipMask: Boolean): Boolean;
var
  NewData: PByte;
  lRawImage: TRawImage;
  lBitmap: TCDBitmap;
begin
  {$ifdef VerboseCDBitmap}
  DebugLn(Format(':[TCDWidgetSet.RawImage_CreateBitmaps]
ARawImage.Description=%s', [ARawImage.Description.AsString]));
  {$endif}

  Result := False;
  ABitmap := 0;
  AMask := 0;

  // Copy the data
  if ARawImage.DataSize  0 then
  begin
NewData := AllocMem(ARawImage.DataSize); -
System.Move(ARawImage.Data^, NewData^, ARawImage.DataSize);
  end
  else
NewData := nil;
  {$ifdef VerboseCDBitmap}
  DebugLn(Format(':[TCDWidgetSet.RawImage_CreateBitmaps] Data=%x Data
size=%d NewData=%x',
[PtrUInt(ARawImage.Data), ARawImage.DataSize, PtrUInt(NewData)]));
  {$endif}

  // this is only a rough implementation, there is no check against bitsperpixel
  lBitmap := TCDBitmap.Create;
  ABitmap := HBITMAP(lBitmap);
  System.Move(ARawImage, lRawImage, SizeOf(TRawImage));
  lRawImage.Data := NewData; -
  lBitmap.Image := TLazIntfImage.Create(lRawImage, True); -
  Result := ABitmap  0;

This shows like this in the log:

:[TCDWidgetSet.RawImage_CreateBitmaps] Data=B73FCC90 Data size=3600
NewData=B73FE360

And later on:

Marked memory at $B73FE360 invalid --- Same address!
Wrong signature $ instead of AFB54FD8
  $08065DDB
  $08065E97
  $0805C888
  $0812AADC  TLAZINTFIMAGE__DESTROY,  line 3244 of intfgraphics.pas
  $08057AD2
  $08057AD2
  $0817F638  TCDWIDGETSET__DELETEOBJECT,  line 863 of
./customdrawn/customdrawnwinapi.inc
  $0816DF1F  DELETEOBJECT,  line 181 of ./include/winapi.inc
  $080FDC1E  TSHAREDRASTERIMAGE__FREEHANDLE,  line 40 of
./include/sharedrasterimage.inc

I use AllocMem and TLazIntfImage uses:

procedure TLazIntfImage.FreeData;
begin
  if FDataOwner
  then ReallocMem(FRawImage.Data, 0)


-- 
Felipe Monteiro de Carvalho

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Memory corruption investigation

2012-03-22 Thread Felipe Monteiro de Carvalho
Ok, I found it! =D

Fixed in rev 36215.
-- 
Felipe Monteiro de Carvalho

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Memory corruption investigation

2012-03-21 Thread Felipe Monteiro de Carvalho
Aha, I think it has nothing to do with the Pen ... I hate when various
DebugLn calls get out of sync and override one another.

Still open to suggestions of how to debug this =)

The error is a crash freeing TLazIntfImage when it frees the data.

-- 
Felipe Monteiro de Carvalho

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Memory corruption investigation

2012-03-21 Thread Mattias Gaertner
On Wed, 21 Mar 2012 11:33:22 +0100
Felipe Monteiro de Carvalho felipemonteiro.carva...@gmail.com wrote:

 Hello,
 
 I thought that maybe someone might have an idea about how to
 investigate an issue of memory corruption / freeing unallocated area:

Have you tried the keepreleased?

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus