Consider the following code:
int main()
{
char* s = (char*) malloc(sizeof(char)*10);
s="hello";
free(s);
}
When executing this program I get an error:
** glibc detected *** free(): invalid pointer: 0x0000000000400b2c
My research on this error indicates it may be caused by not assigning enough memory space via malloc()
. But the program already calls malloc()
, producing enough space for 10 char
s.