I have a class that contains file handle fHandle that points to an open file. Now, it can be closed by any one of the multiple routines and that is based on dynamic run of the program.
To be sure that a file is indeed closed, I put simple snippet in my destructor: if(fHandle!=NULL) fclose(fHandle);. Turns out, if one of the routines had previously closed this file, then the running the destructor snippet causes double free operation and I get **glib detected** error message.
How do I make sure that I don’t close the file handle that has previously been closed (apart from putting NULL check)?
You say you’ve tried:
To avoid a double
fclose(), just setfHandletoNULLwhereever else you may callfcloseon that handle, so the above code in the destructor won’t pass the conditional test….