Possible Memory Leak

I have stumble upon something that I can’t explain:

I’m investigating a memory leak, having pin point where
this is happening I still couldn’t explain it. I’m using a routine
to dump the block in the heap.

I have noted important stuff with “a)” and
attach explanation to each item.

USED block at 000f:01ed152c of size 0090 = 144
USED block at 000f:01ed15bc of size 0040 = 64
USED block at 000f:01ed15fc of size 0020 = 32
USED block at 000f:01ed161c of size 20008 = 131080
USED block at 000f:01ef1624 of size 20008 = 131080
USED block at 000f:01f1162c of size 7A148 = 500040
USED block at 000f:01f8b774 of size 2F08 = 12040
USED block at 000f:01f8e67c of size BBA8 = 48040
USED block at 000f:01f9a224 of size 2F08 = 12040
FREE block at 000f:01f9d12c of size 4953C = 300348
a) FREE block at 000f:0208202c of size 5A034 = 368692
— END OF HEAP DUMP —

before malloc Size:1474560
b) 23462552 669112
after Mem Alloc 02082048
c) 24937152 669172
USED block at 000f:01f1162c of size 7A148 = 500040
USED block at 000f:01f8b774 of size 2F08 = 12040
USED block at 000f:01f8e67c of size BBA8 = 48040
USED block at 000f:01f9a224 of size 2F08 = 12040
FREE block at 000f:01f9d12c of size 4953C = 300348
d) USED block at 000f:0208202c of size 168028 = 1474600
e) FREE block at 000f:021ea054 of size 5A070 = 368752
— END OF HEAP DUMP —zzz

a) This free block is the result of a malloc/free done previously
The requested size was 368640. Everything look good so far.
Address of the block is :0208202c
b) This is the used and free heap size before allocating 1.4Meg
c) This is after allocating 1.4, it apperears it could
find any room in the free heap thus the heap was grown.
Make sense
d) This is the USED block, but do you noticed something,
it’s the same address as the previous 360K block
that was freed. So that means the 360K block
was the last one and it was able to extend it to accomodate
the 1.4M. So the heap should have only grow by 1.4M - 360K.
But this is not what c) showed. Free head is almost the same???
e) What the hell is that FREE block doing there? For some
reason a FREE block was allocated AFTER the 1.4Meg. Thus
taking away from the OS an extra 360k???

The only explanation I can think of is that it’s either a bug,
or some type of optimisation perform by the memory allocator
to prepare big block for possible futur request. Since
requesting memory to the OS is costly CPU cycles wise
this type of optimisation “could” make sense.

Does that make sense???

  • Mario
    “People looking to serious, should be looking to Sirius”