diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2021-09-22 11:47:22 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2021-09-23 05:31:16 +0000 |
commit | e60951eef4f0ade944e2f93ffe2f44abfc76d97a (patch) | |
tree | 044ab5f384258b3dd3f6f19b640e26238856aee4 | |
parent | a4e41e7ac42f835015bdca395a34e5bca7eda86c (diff) |
QFileSystemWatcher: fix QWindowsFileSystemWatcherEngine crashes
Since QHash in Qt6 does not guarantee stable iterators after
an insert it crashed from time to time.
- possible crash at the erase call if pit is invalid
- possible crash at insert if pit is invalid
QHash<QString, int> myHash;
auto i = myHash.find("foo");
myHash.insert("foo", 789);
i.value(); // possible crash
myHash.erase(i); // possible crash
Pick-to: 6.2 dev
Task-number: QTBUG-96790
Change-Id: Ia9b53d46b8d1fef81ab5a130c229bc9e936f6521
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_win.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 31c6b747a7..5d8a5b3682 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -430,8 +430,9 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, FindCloseChangeNotification(hit.value().handle); thread->handles[index] = hit.value().handle = fileHandle; hit.value().flags = flags; - thread->pathInfoForHandle.insert(fileHandle, pit.value()); + auto value = std::move(*pit); thread->pathInfoForHandle.erase(pit); + thread->pathInfoForHandle.insert(fileHandle, std::move(value)); } } // In addition, check on flags for sufficient notification attributes |