V1005. The resource was acquired using 'X' function but was released using incompatible 'Y' function.


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);

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-404.

You can look at examples of errors detected by the V1005 diagnostic.


Bugs Found

Checked Projects
363
Collected Errors
13 495