You seem to be preoccupied with the idea that files may stay away from some due to some race conditions, I donβt see an explanation of why this is troubling.
"A race condition occurs when a program does not work as intended, due to an unexpected ordering of events that give rise to a conflict over the same resource."
I assumed that from your comments on other answers, your concern was specifically about the deadlock, which is the result of an attempt to fix the state of the race (approval of a shared resource). It is not yet clear what your problem is, calling tmpfile() and causing the program to run abnormally before this function calls the unlink() call is the least of your problems if your application is really fragile.
Given that there is no mention of concurrency, streaming, or other processes sharing this file descriptor in this temporary file, I still do not see the possibility of a race condition, perhaps the concept of an incomplete logical transaction, but this can be detected and cleared.
The right way to make sure that all the allocated file system resources are cleared, not only on the application output , but also on before . All my server code, make sure everything is cleared from the previous run before , and it becomes available.
Put your temporary files in a sub-dir in /tmp to make sure your application clears this sub-directory at startup and shutdown normally. You can complete the launch of the application using a shell script that detects abnormal ( kill -9 ) PID based shutdowns and also cleans up actions.
source share