Record state when tmpnam() is called with a NULL parameter.
Include <cstdlib> for std::exit().
Fix a possible null pointer dereference and silence two Clang analyzer warnings.