consider the following:
int * i = malloc(sizeof(int));
free(i);
I am now in a scenario where i
points to deallocated memory, but it is also non-zero; this is a common error in C programming, is there a way to tell that i
is still a valid pointer before I go and do something like:
*i++; //probable EXC_BAD_ACCESS crash
I know that it is completely impossible for there to be a 100% reliable (no false positives) method, unless you never reused memory; but something that worked most of the time would be great for debugging.
edit
I am not arguing that you shouldn't set your pointers to NULL, I am just wondering if there is a portable (POSIXish) way to poke an address without catastrophic repercussions, I just have an interest in debugging complicated multithreaded problems that arise from time to time.