Log in

No account? Create an account
MALLOC_PERTURB_ - Ulrich Drepper [entries|archive|friends|userinfo]
Ulrich Drepper

[ website | My Website ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

MALLOC_PERTURB_ [Jun. 21st, 2006|04:55 pm]
Ulrich Drepper
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_ to 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.