Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-10

StrDispose FreeMem with size

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Micha Nelissen

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

Reply by email

Peter Vreman
to Micha Nelissen
Show quoted text 5 lines
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 ?

The size parameter is ignored by the heap manager.

Reply by email

Micha Nelissen
to Peter Vreman
Peter Vreman wrote 7 lines
> 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 ? The size parameter is ignored by the heap manager.

That's two bugs, then :).

Micha

Reply by email

Daniël Mantione
to Micha Nelissen

Op Fri, 13 Oct 2006, schreef Micha Nelissen:

Show quoted text 11 lines
Peter Vreman wrote: > > 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 ? > > The size parameter is ignored by the heap manager. That's two bugs, then :).

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

Reply by email

Micha Nelissen
to Daniël Mantione
Daniël Mantione wrote 6 lines
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.

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

Reply by email

Daniël Mantione
to Micha Nelissen

Op Fri, 13 Oct 2006, schreef Micha Nelissen:

Show quoted text 18 lines
Daniël Mantione wrote: > 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. 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 ?

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

Reply by email

Micha Nelissen
to Daniël Mantione
Daniël Mantione wrote 6 lines
> I think no recent heap manager can free blocks partially ? 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.

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

Reply by email

Jonas Maebe
to Micha Nelissen
Micha Nelissen wrote 8 lines
Daniël Mantione wrote: >> I think no recent heap manager can free blocks partially ? > 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. I see. I do wonder how many people use their own heap manager though ;-)

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

Reply by email

Micha Nelissen
to Jonas Maebe
Jonas Maebe wrote
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.

Hmm interesting. So 2.1.1 compiled with heaptrace should give this runtime error, if my original post is correct.

Micha

Reply by email

Jonas Maebe
to Micha Nelissen
Micha Nelissen wrote 7 lines
Jonas Maebe wrote: > 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. Hmm interesting. So 2.1.1 compiled with heaptrace should give this runtime error, if my original post is correct.

Yes.

Jonas

Reply by email

Peter Vreman
to Micha Nelissen: I see. I do wonder how many people use their own heap manager though ;-). But more to the…
Show quoted text 11 lines
Daniël Mantione wrote: >> I think no recent heap manager can free blocks partially ? > > 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. 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 ?

For example heaptrc can still use it.

Reply by email

Florian Klaempfl
to Micha Nelissen: I see. I do wonder how many people use their own heap manager though ;-). But more to the…
Micha Nelissen wrote 10 lines
Daniël Mantione wrote: >> I think no recent heap manager can free blocks partially ? > > 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. I see. I do wonder how many people use their own heap manager though ;-).

cmem? sharemem?

Reply by email