The analyzer has detected a possible error that has to do with using incompatible functions to acquire and release a resource.
For example, this warning will be issued when a file is opened using the 'fopen_s' function and closed using the 'CloseHandle' function.
Consider the following example.
FILE* file = nullptr;
errno_t err = fopen_s(&file, "file.txt", "r");
...
CloseHandle(file);
The result of executing this code is unknown. The 'CloseHandle' function may return the error status and merely cause a resource leak (fail to close the file), but more severe implications are also possible. Incorrect calls of some functions lead to undefined behavior, which means unpredictable results, including a crash.
This is what the fixed code should look like:
FILE* file = nullptr;
errno_t err = fopen_s(&file, "file.txt", "r");
...
fclose(file);
This diagnostic is classified as:
You can look at examples of errors detected by the V1005 diagnostic. |
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders:
Take
a chance!