A service that has a background transfer file on the server is frequently reported as an exception and can only be forcibly terminated and restarted.
Yesterday was just free, the scene grabbed a dump, and then threw the program into IDA to see a bit, quickly find out why, the original call fclose error.
Using the C runtime function for file operations, which is fopen,fread,ftell,fclose, is not a problem in itself.
But the location of the exception to the previous point, the program wrote a log, the main content is "Open file failed, error reason: xxxxxx"
That is, after the file has failed to open with fopen, the program still uses fclose to close the invalid file pointer, causing the exception to occur.
You can simply test it with the following code:
voidTestfun () {FILE*FP; FP= fopen ("C:\\nosuchfile.sys","R");//open a file that does not existprintf"fp = 0x%x\n", FP); if(fp = =NULL) {printf ("Open file failed.\n"); } Else{printf ("Open file succeed.\n"); } fclose (FP);//this throws an exception}
In fact, as I know, closing an invalid handle with CloseHandle also throws an exception.
Originally opened operation is a failure, the file pointer is not valid, and then what is the significance of it?
Solution: Directly to the program in the call to a patch, with NOP instructions to fill a bit, it is normal. As shown, the color three instructions are populated with NOP:
An exception thrown by improper use of fclose