Originally Posted by
Salem
Which OS are you running? If it's Linux, you should be able to use valgrind to tell you a lot more about how you're mis-using memory.
p = malloc(10);
strcpy(p,"hello world");
free(p);
Buffer overruns can cause all sorts of difficulty for the memory pool manager, including believing that the block wasn't allocated.
p = malloc(20);
strcpy(p,"hello world");
p = p + 6; // point to world
free(p);
Messing about with the start pointer could result in FUM.
p = malloc(20);
strcpy(p,"hello world");
free(p);
free(p); // oops
Trying to free the same block twice could result in FUM.