On 07/20/2016 03:35 PM, John E. Malmberg wrote:
> If I could get the heap tracking information for a pointer returned from
> malloc() I could probably find where the issue is.
The usual one in the CRTL or the one with the heap analyzer?
Dunno whether this helps or you already know this. It looks like there
are two quadwords just below the malloced memory (the address returned),
which seem to keep track of the allocated memory. The info which I can
identify is the size of the malloced memory - including the two
quadwords - and a flag 0xF00D marking it used.
(Then there may be pointer to the start of the unallocated memory, but
other than that and its size I don't think that there is tracking
information.)
If the memory is freed the flag is changed to 0x7777. And it seems the
free memory is put at the beginning of a "free list". The next pointer
in this list is at the first longword of the previously allocated
memory. It is a zero terminated list.
This is what I see with a simple example in the debugger -
interpretation and/or mis-interpretation is owned by me:-):
DBG> Step
stepped to F\f\%LINE 2
2: int i = 32;
DBG> Step
stepped to F\f\%LINE 4
4: p1=malloc(i);
DBG> Step
stepped to F\f\%LINE 5
5: p1[0]=0x01;
DBG> Step
stepped to F\f\%LINE 6
6: p1[i-1]=0x11;
DBG> Step
stepped to F\f\%LINE 8
8: p2=malloc(i);
DBG> Step
stepped to F\f\%LINE 9
9: p2[0]=0x02;
DBG> Step
stepped to F\f\%LINE 10
10: p2[i-1]=0x22;
DBG> Step
stepped to F\f\%LINE 12
12: p3=malloc(i);
DBG> Step
stepped to F\f\%LINE 13
13: p3[0]=0x03;
DBG> Step
stepped to F\f\%LINE 14
14: p3[i-1]=0x33;
DBG> Step
stepped to F\f\%LINE 16
16: free(p2);
DBG> ex p1, p2, p3
F\f\p1: 002BA010
F\f\p2: 002BA040
F\f\p3: 002BA070
DBG> ex 002BA010-20:002BA070+20+20
00000000002B9FF0: 0000000000000000
00000000002B9FF8: 0000000000000000
00000000002BA000: 0F00D003300000030
00000000002BA008: 0000000000000000
00000000002BA010: 0000000000000001
00000000002BA018: 0000000000000000
00000000002BA020: 0000000000000000
00000000002BA028: 1100000000000000
00000000002BA030: 0F00D003300000030
00000000002BA038: 0000000000000000
00000000002BA040: 0000000000000002
00000000002BA048: 0000000000000000
00000000002BA050: 0000000000000000
00000000002BA058: 2200000000000000
00000000002BA060: 0F00D003300000030
00000000002BA068: 0000000000000000
00000000002BA070: 0000000000000003
00000000002BA078: 0000000000000000
00000000002BA080: 0000000000000000
00000000002BA088: 3300000000000000
00000000002BA090: 0000000000000000
00000000002BA098: 0000000000000000
00000000002BA0A0: 0000000000000000
00000000002BA0A8: 0000000000000000
00000000002BA0B0: 0000000000000000
DBG> Step
stepped to F\f\%LINE 17
17: free(p3);
DBG> ex 002BA010-20:002BA070+20+20
00000000002B9FF0: 0000000000000000
00000000002B9FF8: 0000000000000000
00000000002BA000: 0F00D003300000030
00000000002BA008: 0000000000000000
00000000002BA010: 0000000000000001
00000000002BA018: 0000000000000000
00000000002BA020: 0000000000000000
00000000002BA028: 1100000000000000
00000000002BA030: 7777003300000030
00000000002BA038: 0000000000000000
00000000002BA040: 0000000000000000
00000000002BA048: 0000000000000000
00000000002BA050: 0000000000000000
00000000002BA058: 2200000000000000
00000000002BA060: 0F00D003300000030
00000000002BA068: 0000000000000000
00000000002BA070: 0000000000000003
00000000002BA078: 0000000000000000
00000000002BA080: 0000000000000000
00000000002BA088: 3300000000000000
00000000002BA090: 0000000000000000
00000000002BA098: 0000000000000000
00000000002BA0A0: 0000000000000000
00000000002BA0A8: 0000000000000000
00000000002BA0B0: 0000000000000000
DBG> Step
stepped to F\f\%LINE 18
18: free(p1);
DBG> ex 002BA010-20:002BA070+20+20
00000000002B9FF0: 0000000000000000
00000000002B9FF8: 0000000000000000
00000000002BA000: 0F00D003300000030
00000000002BA008: 0000000000000000
00000000002BA010: 0000000000000001
00000000002BA018: 0000000000000000
00000000002BA020: 0000000000000000
00000000002BA028: 1100000000000000
00000000002BA030: 7777003300000030
00000000002BA038: 0000000000000000
00000000002BA040: 0000000000000000
00000000002BA048: 0000000000000000
00000000002BA050: 0000000000000000
00000000002BA058: 2200000000000000
00000000002BA060: 7777003300000030
00000000002BA068: 0000000000000000
00000000002BA070: 00000000002BA040
00000000002BA078: 0000000000000000
00000000002BA080: 0000000000000000
00000000002BA088: 3300000000000000
00000000002BA090: 0000000000000000
00000000002BA098: 0000000000000000
00000000002BA0A0: 0000000000000000
00000000002BA0A8: 0000000000000000
00000000002BA0B0: 0000000000000000
DBG> Step
stepped to F\f\%LINE 19
19: }
DBG> ex 002BA010-20:002BA070+20+20
00000000002B9FF0: 0000000000000000
00000000002B9FF8: 0000000000000000
00000000002BA000: 7777003300000030
00000000002BA008: 0000000000000000
00000000002BA010: 00000000002BA070
00000000002BA018: 0000000000000000
00000000002BA020: 0000000000000000
00000000002BA028: 1100000000000000
00000000002BA030: 7777003300000030
00000000002BA038: 0000000000000000
00000000002BA040: 0000000000000000
00000000002BA048: 0000000000000000
00000000002BA050: 0000000000000000
00000000002BA058: 2200000000000000
00000000002BA060: 7777003300000030
00000000002BA068: 0000000000000000
00000000002BA070: 00000000002BA040
00000000002BA078: 0000000000000000
00000000002BA080: 0000000000000000
00000000002BA088: 3300000000000000
00000000002BA090: 0000000000000000
00000000002BA098: 0000000000000000
00000000002BA0A0: 0000000000000000
00000000002BA0A8: 0000000000000000
00000000002BA0B0: 0000000000000000
DBG>