does a content of a pointer is zero after freeing that pointer???
Printable View
does a content of a pointer is zero after freeing that pointer???
No, not in and of itself. It is customary to set the pointer to NULL (zero) when freeing it, but there is no automatic way that this is done. I have occassionally suggested a function like this:
--Code:void freeAndNull(void **p)
{
if(p) // It is possible that someone by mistake is passing NULL as the parameter to freeAndNull...
{
free(*p);
*p = NULL;
}
}
// And an example call:
char * p = malloc(...);
...
freeAndNull(&p);
...
Mats
If you ever get to a point where you are writing your own memory manager you may find that there are many disadvantages to trying to zero out every block of deallocated memory. It should only be an issue when dealing with security. Other than that, it is a good way to slow down your memory management functions.