i have an assigment to fork the main program to 4 sons
each will sort an array in a different way
for (sonID=0;sonID<4;sonID++)
{
status=fork();
if (status<0)
error("Can't Fork!");
if (status==0)
{
checkFiles(argc,argv,&in,&out,sonID);// opening the files for use
readFromFile(&nameList,&sizeOfList,&numOfStrings,in);
sortArray(numOfStrings,&nameList,sonID);
outputToFile(nameList,numOfStrings,out); //output the array to out file
freeArray(sizeOfList,nameList); //freeing the whole array cells
closeFiles(&in,&out); // closing the files
}
}
for (sonID=0;sonID<4;sonID++)
{
wait(&status);
}
now if i call freeArray i get
*** glibc detected *** double free or corruption (fasttop): 0x09fb94e8 ***
and first file has the array 2nd file has 2xarray 3rd has 4xarrays etc...
and if i dont call it the files dont have anything in them except the first one
any ideas?
freeArray is simple
void freeArray(const int sizeOfList,char **nameList)
{
int index;
for (index=0;index<sizeOfList;index++)
free (nameList[index]);
free(nameList);
}
and here is the opening file function (dont think the problam is there but who knows )
char *fileName;
switch(sonID){
case(SONONE):fileName="id_up.out";
break;
case(SONTWO):fileName="name_down.out";
break;
case(SONTHREE):fileName="name_up.out";
break;
case(SONFOUR):fileName="id_down.out";
break;
default:break;
}
if (argc!=CORRECT_PARAMETERS) error("Bad Number of parameters");
if (argc>FIRST_INPUT)
{
*in = fopen(argv[FIRST_INPUT], "r");
if (*in==NULL)
error("Can't open input file");
}
else
error("No 1st Input. go to README for insturctions.");
*out = fopen(fileName, "w");
if (*out==NULL) error("Can't open output file");
cheers thanks!