CloseHandle (): checking for return value is required

I use CloseHandle() to close the stream handle. This is done at the end of the program, and therefore the cleanup operation should be independent of the return value of CloseHandle

pc-lint reports an error, ignoring the return value of the function.

Please let me know if there will be any problem if you ignore the return value.

+4
source share
1 answer

The simple answer is: I don’t think I have ever seen any code anywhere that checks the return value of CloseHandle, and CloseHandle does not work, has never been the cause of any error that I have ever seen in 15+ years Windows Programming (YMMV).

The real answer: Of course, you should check the error return (from all the methods that could return a failure, all the time), assuming that your application has a constant error handling structure already in place, you will simply work with it. Failure to consistently check return values ​​and assume success is a recipe for larger, often more difficult to understand, crashes later in the code.

That said: I'm worried that CloseHandle fails while shutting down the application? Probably no. But this is only my 2 cents.

+3
source

Source: https://habr.com/ru/post/1299336/


All Articles