>
>
>
V1005. The resource was acquired using …


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

This diagnostic is classified as:

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