From fc6eb0bb7ef6b68508633eb7a4aa6193fe29a833 Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Wed, 22 Sep 2021 11:47:22 +0200 Subject: [PATCH] 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 myHash; auto i = myHash.find("foo"); myHash.insert("foo", 789); i.value(); // possible crash myHash.erase(i); // possible crash Task-number: QTBUG-96790 Change-Id: Ia9b53d46b8d1fef81ab5a130c229bc9e936f6521 Reviewed-by: Thomas Hartmann Reviewed-by: Lars Knoll (cherry picked from commit e60951eef4f0ade944e2f93ffe2f44abfc76d97a) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qfilesystemwatcher_win.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 31c6b747a76..5d8a5b36826 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