Code snippet, at the bottom, which I was trying lead to the following error
free(): invalid next size (fast)
Above error, was caused by declaration of integer variable mock after accidently calling memset() on pointer check with size more than what was originally allocated using malloc(). And when free() is called on pointer check it leads to a runtime error.
It would be helpful if somebody could explain how the internal memory is being manipulated or why this error actually occurred.
Thanks in advance.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *check = (char *)malloc(sizeof(char) * 10);
memset(check, 0, 100);
memcpy(check, "memsetcpy", 10);
int mock = 9;
free(check);
return 1;
}
EDIT My intention of asking the question was to know/understand what happens to the book-keeping information in the heap memory when the program runs. And may be to have some information on data structures that are modified would be great. OR I wanted to know from the design perspective.
Thanks everyone for chipping-in.