>Well, I would say just free() it either way.
You're relying on undefined behavior.
There is no safe, portable way to determine if a pointer points to dynamic memory memory or not. Fix your design so that you aren't forced to perform such a test.184.108.40.206
... If ptr is a null pointer, no action occurs. Otherwise, if the argument does not match a pointer earlier returned by the calloc, malloc, realloc function, or if the space has been deallocated by a call to free or realloc, the behavior is undefined.