[fpc-devel] Const optimization is a serious bug

Martin fpc at mfriebe.de
Tue Jul 5 17:41:54 CEST 2011


On 05/07/2011 16:28, Florian Klaempfl wrote:
> As written in some of the bug reports, I consider as a better solution:
> - Pointer checking of constant parameters of types like ansistrings,
> interfaces at procedure exit. Together with heaptrc and keep_released
> enabled, this catches all cases of disposed const parameters and
> probably a lot more pointer errors.
> - Like the scrambling of local parameters with -gttt, some checksumming
> for contant parameters could be implemented. This catches not only the
> modified constant parameter but also aliasing problems.

There would be the possibility to extend heaptrc mem manager.
Every mem block gets a "release-lock"- or const-counter (and maybe a 
checksum field).

then any memory used in a const param, can be protected (via the mem 
manager) against release (ONLY if compiled with sanity check).

That would catch the releases due to refcount going to 0, were it must 
not be allowed.

The checksum can be used for general checking.

The checksum should be toggle-able by a 2nd switch (and maybe with a 
configurable upper limit for mem size, so to skip tests for very large data)


Variables on the stack, do not get the mem-alloc protection => but they 
can not be released early anyway



More information about the fpc-devel mailing list