I would like to know whether the dynamic memory pointer is still available even after freeing the allocated memory. If I want to allocate and deallocate so many times within a loop , I receive memory corruption. Pls help me how I should do.If I call "free" more than one time, it reports error because allocated memory is already freed even though there is still available. I don't understand this concept . Pls help me.The program is as follows.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
int i = 0;
unsigned char* temp = NULL;
unsigned char st[] = "Hello";
for ( i = 0;i < 10;i++)
{
temp = (unsigned char*) malloc( strlen(st) );
memcpy( temp, st, strlen(st));
if (temp)
free(temp);
if (temp)
printf("still available");
else
printf("already destroyed");
if (temp)
free(temp);
}
}