[PATCH] D36529: Fixed a race condition in PrecompiledPreamble.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 10 03:39:44 PDT 2017


ilya-biryukov added inline comments.


================
Comment at: lib/Frontend/PrecompiledPreamble.cpp:470-471
+  int FD;
+  auto EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, /*ref*/ FD,
+                                               /*ref*/ File);
   if (EC)
----------------
klimek wrote:
> I don't understand that yet - why does keeping the file open around the EC check change any of the behavior?
> Generally, both create the file, right? So only the first one should get no error?
`createTemporaryFile` without `fd` does not create a file, only checks if the it exists, hence the race condition. Do you think a better solution would be to make it create an empty file and close it right away, similarly to what this function does now?

`createTemporaryFile` with `fd` does not have that problem, it actually tries to create a file until it succeeds.


https://reviews.llvm.org/D36529





More information about the cfe-commits mailing list