You can't. The way to track this would be to assign the pointer to 0
or NULL
after freeing it. However as Fred Larson mentioned, this does nothing to other pointers pointing to the same location.
int* ptr = (int*)malloc(sizeof(int));
free(ptr);
ptr = NULL;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…