summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-06-25 10:21:57 +0200
committerMarc Mutz <[email protected]>2025-06-26 06:16:31 +0200
commit5a567e3ed2a0181d88b2f22b844852a23222a168 (patch)
tree1a7a6f87692b12a35c52e790d6b5d0e4abeec939
parentcd4813a3c304a6d9d5d8096d91a8fc297818d624 (diff)
QLockFilePrivate: de-inline all functionsHEADdev
This class is going to be marked as security-critical, and so we don't want code in the header (because fixes in inline code require recompiling all users, not just re-linking). Incidentally, de-inlining getLockFileHandle() removes the need to include some nasty (qt_windows.h) headers in the header (which means we need to revert part of 779bdf481ca208c20cfabd02d02d74175b0624b9 and go back from NSDMI to ctor-init-list, at least for `fileHandle`). As a drive-by, make the constructor explicit. Pick-to: 6.10 6.9 6.8 6.5 Change-Id: I3d376c2c02eb1f7de7a0b923ac4424b1057fdb1c Reviewed-by: David Faure <[email protected]>
-rw-r--r--src/corelib/io/qlockfile.cpp33
-rw-r--r--src/corelib/io/qlockfile_p.h32
2 files changed, 40 insertions, 25 deletions
diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp
index e4dd74152a2..885d68a07d1 100644
--- a/src/corelib/io/qlockfile.cpp
+++ b/src/corelib/io/qlockfile.cpp
@@ -12,6 +12,13 @@
#include <QtCore/qdatetime.h>
#include <QtCore/qfileinfo.h>
+#include <qplatformdefs.h>
+
+#ifdef Q_OS_WIN
+#include <io.h>
+#include <qt_windows.h>
+#endif
+
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
@@ -368,6 +375,19 @@ bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) co
return true;
}
+QLockFilePrivate::QLockFilePrivate(const QString &fn)
+ : fileName(fn),
+#ifdef Q_OS_WIN
+ fileHandle(INVALID_HANDLE_VALUE)
+#else
+ fileHandle(-1)
+#endif
+{
+}
+
+QLockFilePrivate::~QLockFilePrivate()
+ = default;
+
QByteArray QLockFilePrivate::lockFileContents() const
{
// Use operator% from the fast builder to avoid multiple memory allocations.
@@ -437,6 +457,19 @@ bool QLockFilePrivate::isApparentlyStale() const
return staleLockTime > 0ms && abs(age) > staleLockTime;
}
+int QLockFilePrivate::getLockFileHandle(QLockFile *f)
+{
+ int fd;
+#ifdef Q_OS_WIN
+ // Use of this function on Windows WILL leak a file descriptor.
+ fd = _open_osfhandle(intptr_t(f->d_func()->fileHandle), 0);
+#else
+ fd = f->d_func()->fileHandle;
+#endif
+ QT_LSEEK(fd, 0, SEEK_SET);
+ return fd;
+}
+
/*!
Attempts to forcefully remove an existing lock file.
diff --git a/src/corelib/io/qlockfile_p.h b/src/corelib/io/qlockfile_p.h
index 299b13b21a2..02a5f8be2e4 100644
--- a/src/corelib/io/qlockfile_p.h
+++ b/src/corelib/io/qlockfile_p.h
@@ -19,22 +19,14 @@
#include <QtCore/qlockfile.h>
#include <QtCore/qfile.h>
-#include <qplatformdefs.h>
-
-#ifdef Q_OS_WIN
-#include <io.h>
-#include <qt_windows.h>
-#endif
-
QT_BEGIN_NAMESPACE
class QLockFilePrivate
{
public:
- QLockFilePrivate(const QString &fn)
- : fileName(fn)
- {
- }
+ explicit QLockFilePrivate(const QString &fn);
+ ~QLockFilePrivate();
+
QLockFile::LockError tryLock_sys();
bool removeStaleLock();
QByteArray lockFileContents() const;
@@ -49,27 +41,17 @@ public:
QString fileName;
#ifdef Q_OS_WIN
- Qt::HANDLE fileHandle = INVALID_HANDLE_VALUE;
+ Qt::HANDLE fileHandle;
#else
- int fileHandle = -1;
+ int fileHandle;
#endif
std::chrono::milliseconds staleLockTime = std::chrono::seconds{30};
QLockFile::LockError lockError = QLockFile::NoError;
bool isLocked = false;
- static int getLockFileHandle(QLockFile *f)
- {
- int fd;
-#ifdef Q_OS_WIN
- // Use of this function on Windows WILL leak a file descriptor.
- fd = _open_osfhandle(intptr_t(f->d_func()->fileHandle), 0);
-#else
- fd = f->d_func()->fileHandle;
-#endif
- QT_LSEEK(fd, 0, SEEK_SET);
- return fd;
- }
+ // used in tst_QLockFile:
+ Q_CORE_EXPORT static int getLockFileHandle(QLockFile *f);
};
QT_END_NAMESPACE