I read a lot about fclose and I have 2 questions about it:
1) my program crashes after a call to fclose(pFile), even though I checked that Pfile isn't NULL, and change it to NULL right after fclose. (see code below)
I have to mention that the crash doesn't happen any time the program run, but only at specific circumstances which I still don't know exactly what are they.
after the crash , I get an error - double free or corruption (!prev). so I guess it means that somehow fclose is being called twice on the same file descriptor, what I don't understand is how could this possibly happen?
if (NULL != pFile)
{
fclose(pFile);
pFile=NULL;
}
pFile = fopen (fullFilePath.c_str(), "r");
2) I know that calling fclose twice on the same file descriptor usually leads to crash, but I couldn't find an answer in the case that I have 2 file descriptors to the same file (lets say that there are 2 threads of the same process - each holds one file descriptor) . in this case, if both threads calling to fclose on the same file but through two different file descriptors, is that ok? it won't cause a crash?