Suppose I allocate a piece of dynamic memory, and it was successful. Later on, there is a possibility that this piece of memory no longer belongs to the user. Is it possible to determine if the user still owns this piece of dynamic memory? i.e.
int* ptr = malloc(sizeof(int));
/* ... ptr may have been freed ... */
belongToUser(ptr); /* <- some sort of check? */
There is a (neither clean nor safe) possibility to check:
As mentioned, I'd never recommend to check, but to write C programs that remember (
pointer = NULL).