A stream or directory is closed twice

tx0/cpp:double-closedefaultwarningreliability/api-misusedepth fastbug, cwe-1341

What it finds

fclose(f); and later fclose(f); again on some path: the second call closes a stream that no longer exists, which is undefined and may close a stream opened since in its place. The same holds for pclose and closedir.

``cpp fclose(out); if (failed) { fclose(out); // closed above return -1; } ``

The rule follows each function on its paths as double-free does.

From the rule's source, double_close.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:double-close" = "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:double-close] reason="..."

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