Memory is used through a pointer after the pointer was freed
What it finds
delete p; or free(p); and then p->next, p->f(), *p or strlen(p) on some path: the memory is read or written after it was given back, while the allocator may already have handed it out again.
``cpp free(node); if (verbose) log_line("dropped"); next = node->next; // node was freed above ``
The rule follows each function on its paths, keeping apart up to four of them, so a pointer freed on one path and used on another that cannot follow it is not reported: if (err) free(p); ... if (!err) use(p); is fine as long as err is not changed in between. A use is a dereference of the pointer itself, or passing it to a function of the C library that reads what it points to, such as strlen, memcpy or fprintf. Only local variables and parameters are followed, as SSA values, so a pointer that is assigned anew after the call, or whose address is taken, is not reported. Where the file has a translation-unit view, the function is followed after macro expansion. Functions with constructs the lowering does not understand are skipped.
From the rule's source, use_after_free.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:
[rules]
"tx0/cpp:use-after-free" = "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:use-after-free] reason="..."tx0 explain tx0/cpp:use-after-free shows the same in the terminal. Found a false positive? Report it.