[fpc-devel] compile time memory leak detection

Marco van de Voort marcov at stack.nl
Tue Jan 19 21:18:03 CET 2010


In our previous episode, Nikolai Zhubr said:
> >    p: pchar;
> > begin
> >    GetMem(p,10);
> >    inc(p,random(30));
> 
> Yes, this is among things which should probably be immediately 
> disallowed at compile-time (as long as one wants reasonably safe 
> pointers) because they are hard (or expensive) to validate later.

To the compiler random is just another procedure. It doesn't grasp that it
gives back random values.

FPC is not going to forbid standard pointer use, since it breaks a lot of
code.
 
> I usually try to not use raw pointer arithmetics and either use 
> new/dispose with typed pointers or constructs like GetMem(X, 
> SizeOf(X^)). However, compiler does not force me to do so.

In theory, of course a dialect, or dialect switch could be implemented. It
could be even combined with an ISO Pascal mode. But the question is always
who is going to do it, and who is going to support it long term?






More information about the fpc-devel mailing list