[Lazarus] Memory corruption investigation

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Wed Mar 21 11:33:22 CET 2012


Hello,

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

Basically I would like to understand how I can read the info from
heap-trace. I have this:

:>[TCDWidgetSet.CreatePenIndirect]  Style: 0, Color:     D300 Result:"B74D3760
:>[TCDWidgetSet.SelectObject] DC=B74BBBC0 GDIObj=B74D3760
:<[TCDWidgetSet.SelectObject] Result=B74D3860 ObjectType=Pen
....
Trace:> [WinAPI DeleteObject] GDIObject: B74E37E0
Trace:< [WinAPI DeleteObject] Result=True ObjectType=Image
:>[TCDWidgetSet.SelectObject] DC=B74BBAF0 GDIObj=B74D35E0
:<[TCDWidgetSet.SelectObject] Result=B74D34E0 ObjectType=Pen
Trace:> [WinAPI DeleteObject] GDIObject: B74E3600
Marked memory at $B7509820 invalid
Wrong signature $AAAAAAAA instead of 6C48700E
  $0806452B
  $080645E7
  $0805BCE8
  $08126A4C  TLAZINTFIMAGE__DESTROY,  line 3244 of intfgraphics.pas
  $080570D2
  $080570D2
  $0817AAB8  TCDWIDGETSET__DELETEOBJECT,  line 867 of
./customdrawn/customdrawnwinapi.inc
  $081699DF  DELETEOBJECT,  line 181 of ./include/winapi.inc
  $080FB14E  TSHAREDRASTERIMAGE__FREEHANDLE,  line 40 of
./include/sharedrasterimage.inc
Trace:> [WinAPI DeleteObject] GDIObject: B74D3760
Trace:< [WinAPI DeleteObject] Result=True ObjectType=Pen
Trace:> [WinAPI DeleteObject] GDIObject: B74D34E0
Trace:< [WinAPI DeleteObject] Result=True ObjectType=Pen
Heap dump by heaptrc unit
1414 memory blocks allocated : 132878/141032
1359 memory blocks freed     : 123243/131352
55 unfreed memory blocks : 9635
True heap size : 786432
True free heap : 768928
Should be : 773232
Call trace for block $B74F7380 size 17
  $0817A934  TCDWIDGETSET__DELETEOBJECT,  line 795 of
./customdrawn/customdrawnwinapi.inc
  $081699DF  DELETEOBJECT,  line 181 of ./include/winapi.inc
  $080FB14E  TSHAREDRASTERIMAGE__FREEHANDLE,  line 40 of
./include/sharedrasterimage.inc
  $080FB2F9  TSHAREDCUSTOMBITMAP__FREEHANDLE,  line 36 of
./include/sharedcustombitmap.inc
  $080FE400  TCUSTOMBITMAP__SETSIZE,  line 367 of ./include/custombitmap.inc
  $080FD800  TRASTERIMAGE__SETWIDTH,  line 956 of ./include/rasterimage.inc
  $0807F14B  TCDDRAWER__SCALERASTERIMAGE,  line 558 of customdrawndrawers.pas
  $08080720  TCDDRAWERANDROID__LOADRESOURCES,  line 433 of
customdrawn_android.pas
....

Does Heaptrace end the application by itself when it finds the wrong
signature? If yes, why there is after that more DeleteObject calls?

>From what I understand I see that it created a Pen with address
B74D3760 and later tried to free this same object which brought the
error.

So, what happened here? Another code wrong in that address space
allocated for the Pen? Or would the error be in the Pen code itself? I
already read it and can't find any error.

thanks,
-- 
Felipe Monteiro de Carvalho




More information about the Lazarus mailing list