One of the issues with dynamic memory allocation is that one may delete
/free
a block of memory and still have pointers pointing into it. When one dereferences one of these pointers, chances are that things may "work" but leave one vulnerable to memory corruptions etc.
In order to help with these issues some platforms make delete
/ free
write garbage (something like DEDEDEDE
) into the freed heap cell before releasing it as a freed cell. This means that when one tries to now dereference a pointer to a freed cell, one can more or less always expect a data_abort exception which should cause the program to crash. This will when using the debug library. The release library does not do this because of performance reasons.
Could someone tell me if one can get this kind of behavior on standard Linux platforms using glibc or how to perform some simple operation to do this. I think it will help me find some bugs a lot more easily.
I would like to add that it should be trivial to enable or disable this behavior for different builds. The closest thing I can think of is malloc hooks, unfortunately free does not take the cell size as a parameter.