Code : function sSaveTFFile
Code:
.......................
iRetCode = link (caCurrentFilename, caBackupFilename);
if (iRetCode == -1)
{
ERR_MSG2(LOG_ALERT, "Can't move %s to %s", caCurrentFilename, caBackupFilename);
return(FAILURE);
}
iRetCode = unlink (caCurrentFilename);
if (iRetCode == -1)
{
ERR_MSG2(LOG_ALERT, "Can't move %s to %s", caCurrentFilename, caBackupFilename);
return(FAILURE);
}
fpTFFile = fopen (caCurrentFilename, "wb");
if (fpTFFile == NULL)
{
ERR_MSG1 (LOG_ALERT, "Can't open %s\n", caCurrentFilename);
return (FAILURE);
}
/*
the program crashes here while calling the fwrite function.
I have verified all the parameters of fwrite. They are valid pointers. I’ve also tried putting another fwrite function writing a hard coded value into a file. That function also is crashing.
I've replaced fwrite with fprintf, but still getting the same error.
*/
if (fwrite (pCurSectData->pucData, sizeof (Uchar_t), pCurSectData->ulDataSize, fpTFFile)
!= pCurSectData->ulDataSize)
{
ERR_MSG1 (LOG_ALERT, "Can't save modified TF data to %s\n", caCurrentFilename);
return (FAILURE);
}
................................
please find the snapshot of the call stack (while the crash has occurred) in the attachement
Here our function is sSaveTFFile, which calls the fwrite and it is throwing the segmentation fault.
While searching in Google Groups, I found some articles telling the reason to be memory mismanagement. Could any one figure out the exact problem?