x.value = (char*)malloc(sizeof("HelloWorld")); //make x.value point to a memory block allocated by malloc
x.value="HelloWorld"; //now make it point somewhere else - not allocated by malloc
free(x.value);//now try and free the memory that was NOT allocated by malloc - ERROR
Now I have solved the early problem ..but For array of structures..
#define numberPoints 50
struct configStruct
{
char *pointName;
uint2 type;
}conf[numberPoints];
/*This code is executed as many times as number of values in file ,,ie all the pointNames may not be initialised*/
conf[configStructCounter].pointName=(char*)malloc(sizeof(token)); /*token value is read from file*/
strcpy(conf[configStructCounter].pointName,token);
/*Now trying to delete the values*/
for(int delCount=0;delCount<numberofValuesInFile;delCount++)
{
free(conf[delCount].pointName);
}
But here the program throws abort retry ignore screen...
Is this C or C++, if you're using C++ you can add class methods to make this safe. There's no point discussing it futher without knowing the language you're using.
You're asking for trouble by putting code like that into a program. configStruct should be responsible for the allocation and release of its own resources, not the user of configStruct.
This is not C#. Class syntax also apply to struct in C++. You can add methods as you would a class. In practice and syntax there isn't a difference between the two. There's only a semantic difference.