Hello,
I have a code which does malloc and does realloc,but whenever i free i get the fllowing error:
*** glibc detected *** free(): invalid next size (fast): 0x0804a008 ***
the code is as below:
short* p;
short i;
p = (short*)calloc( 10, 2);
for(i = 0; i < 10; i++){
p[i] = i;
}
p = (short*)realloc (p, 20);
for(i = 10; i < 20; i++){
p[i] = i;
}
for(i = 0; i < 20; i++){
printf("%d\n", p[i]);
}
free(p);
return 0;
whats wrong in my code???
I have a code which does malloc and does realloc,but whenever i free i get the fllowing error:
*** glibc detected *** free(): invalid next size (fast): 0x0804a008 ***
the code is as below:
short* p;
short i;
p = (short*)calloc( 10, 2);
for(i = 0; i < 10; i++){
p[i] = i;
}
p = (short*)realloc (p, 20);
for(i = 10; i < 20; i++){
p[i] = i;
}
for(i = 0; i < 20; i++){
printf("%d\n", p[i]);
}
free(p);
return 0;
whats wrong in my code???
Comment