Can somebody please explain me way the free(test[0])
is giving me a segmentation fault (core dumped)
? I've tried to comment out the free and then the program terminates correctly (except from the lost memory). Also if I comment out test[0] = "abcd"
and insert the free(...)
again it terminates correctly too!?
char **test = (char**) (malloc(sizeof(char*) * 5));
for (int i=0; i<5; i++) {
test[i] = (char*) (malloc(sizeof(char*) * 5));
}
test[0] = "abcd";
free(test[0]);