Is there a way to check if a pointer has been free before?
For example, if I run this code:
int* p = (int*)malloc(1000);
free(p);
p = (int*)realloc(p, 2000);
I get the error:
*** Error in `./main': realloc(): invalid old size: 0x00000000012ab010 ***
...
I would like to have an opportunity to check p
before calling realloc
to avoid such errors.