summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qtemporaryfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index ad2b116..4856353 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -219,9 +219,20 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen)
# elif defined(Q_OS_WIN)
|O_BINARY
# endif
+# ifdef O_CLOEXEC
+ // supported on Linux >= 2.6.23; avoids one extra system call
+ // and avoids a race condition: if another thread forks, we could
+ // end up leaking a file descriptor...
+ |O_CLOEXEC
+# endif
, 0600)) >= 0)
#endif // WIN && !CE
+ {
+#if defined(Q_OS_UNIX) && !defined(O_CLOEXEC)
+ fcntl(*doopen, F_SETFD, FD_CLOEXEC);
+#endif
return 1;
+ }
if (errno != EEXIST)
return 0;
} else if (domkdir) {