In c program, why free memory of string (which copy from strcpy) in osx is not woking? [duplicate]
问题 This question already has answers here : Freeing malloced structure in a function (4 answers) Closed 2 years ago . my osx version is 10.12, when I copy string from origin string , then free it, it's not working, But in linux(centos 6.2) is ok, I print copy is invalid. I don't find the reason, It's really confused me. here is code: #include <string.h> #include <stdlib.h> #include <stdio.h> int main(){ char *copy; char *origin = "tutorialspoint"; copy = (char *) malloc(15); strcpy(copy, origin)