Hi,
At cutils line 926, FreeMem is called for p with size strlen(p)+1. Could it be that actually a much bigger block was allocated, and not size strlen(p)+1 ?
Micha

Mailing lists / fpc-devel / 2006-10
13 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
At cutils line 926, FreeMem is called for p with size strlen(p)+1. Could it be that actually a much bigger block was allocated, and not size strlen(p)+1 ?
Micha
The size parameter is ignored by the heap manager.
That's two bugs, then :).
Micha
Op Fri, 13 Oct 2006, schreef Micha Nelissen:
No, it is a concious decision and Delphi compatible. The TP heap manager did not store the size of a block, so the size parameter was necessary. It was also possible to free only parts of blocks.
This is not possible with the FPC heap manager, it frees the entire heap block. So the size has no function.
Daniël
Oh ok, I didn't know; thought it was like an assertion check. But why is there a FreeMemSize in the heap manager then ? It could've been:
function FreeMemSize(P: pointer; S: ptrint): ptrint;
begin
{ ignore S: cannot free blocks partially }
Result := FreeMem(P);
end;I think no recent heap manager can free blocks partially ?
Micha
Op Fri, 13 Oct 2006, schreef Micha Nelissen:
I think the idea is that if you want, you can write and install a heap manager that uses the size. In such case you implement freemem(pointer,size), and freemem(pointer) then results in a runtime error.
Daniël
I see. I do wonder how many people use their own heap manager though ;-). But more to the point: our RTL wont work with this heap manager I guess ? It think it has a lot of freemems without size ?
Micha
heaptrc checks the size parameter if one is given, and gives a run time error if the size does not match the size given at allocation time.
Jonas
Jonas Maebe wroteheaptrc checks the size parameter if one is given, and gives a run time error if the size does not match the size given at allocation time.
Hmm interesting. So 2.1.1 compiled with heaptrace should give this runtime error, if my original post is correct.
Micha
Yes.
Jonas
I see. I do wonder how many people use their own heap manager though ;-). But more to the…
For example heaptrc can still use it.
I see. I do wonder how many people use their own heap manager though ;-). But more to the…
cmem? sharemem?
Of course, but does C free support a size parameter ?
Micha