All of the interesting technological, artistic or just plain fun subjects I'd investigate if I had an infinite number of lifetimes. In other words, a dumping ground...

Tuesday, 18 November 2008

MALLOC_PERTURB_

http://udrepper.livejournal.com/11429.html
MALLOC_PERTURB_

Seems like the number of people who know this feature is still almost zero. Well, RH developers know it and we have some who use it all the time on development machines. Basically, setting this environment variable causes the malloc functions in libc to return memory which has been wiped and clear memory when it is returned. Of course this does not affect calloc which always does clear the memory.

The reason for this exercise is, of course, to f ind code which uses memory returned by malloc without initializing it and code which uses code after it is freed. valgrind can do this but it's costly to run. The MALLOC_PERTURB_ exchanges the ability to detect problems in 100% of the cases with speed.

The byte value used to initialize values returned by malloc is the byte value of the environment value. The value used to clear memory is the bitwise inverse. Setting MALLOC_PERTURB_ ti zero disables the feature.

This technique can find hard to detect bugs. It is therefore suggested to always use this flag (at least temporarily) when testing out code or a new distribution. That's a hint for all the brave souls testing FC6t1.

No comments:

tim's shared items

Add to Google Reader or Homepage