A thread that is detached runs a lambda capturing by reference, which may outlive the variables it refers to
What it finds
A detached thread keeps running after the function that started it returns; a lambda that captures that function's variables by reference then reads and writes freed stack memory. Capturing by value, or joining the thread, keeps the references valid.
From the rule's source, detached_thread_captures_by_reference.rs.
Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/cpp:detached-thread-captures-by-reference" = "warning"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:detached-thread-captures-by-reference] reason="..."tx0 explain tx0/cpp:detached-thread-captures-by-reference shows the same in the terminal. Found a false positive? Report it.