When I look at free()'s manpage, it mentions that its behaviour is undefined if I pass it a pointer which hasn't been returned by malloc(), calloc() or realloc(), or if the pointer I pass to it had the memory it's pointing to "free()'d" before.
What if I pass it a pointer which is a copy of a pointer returned by, say, malloc()? For example:
Is this OK to do, even though the pointer that free() receives is a copy of the original "my_pointer"?Code:(...) void free_int_pointer(int* ptr) { free(ptr); } int main() { int* my_pointer = malloc(sizeof(int)); free_int_pointer(my_pointer); return 0; }
Thank you in advance.