free is given memory that was not allocated on the heap

tx0/cpp:free-non-heapdefaultwarningreliability/memory-safetydepth fastbug

What it finds

free(&x), free(buf) for an array buf, free("text"): memory that malloc did not return cannot be freed, and passing it to free corrupts the heap or crashes.

Counted are the address of a variable, of one of its fields or of an element of an array, an array declared in the file with its brackets in its own declarator and not as a parameter, which would be a pointer, and string literals. The function must be the C library's free.

From the rule's source, free_non_heap.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:free-non-heap" = "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:free-non-heap] reason="..."

tx0 explain tx0/cpp:free-non-heap shows the same in the terminal. Found a false positive? Report it.