A resource is released with the function for another kind of resource

tx0/cpp:release-mismatchdefaultwarningreliability/memory-safetydepth fastbug, cwe-762

What it finds

f = fopen(path, "r"); ... free(f); or p = malloc(n); ... fclose(p);: each kind of resource has its own function to release it, fclose for fopen, pclose for popen, closedir for opendir and free for the allocation functions, and the wrong one corrupts memory or leaks the resource.

The variable must be local to the function and every value assigned to it there must come from functions of the same kind.

From the rule's source, release_mismatch.rs.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:release-mismatch" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/cpp:release-mismatch] reason="..."

tx0 explain tx0/cpp:release-mismatch shows the same in the terminal. Found a false positive? Report it.