diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-16 13:29:22 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-04-01 21:33:57 +0100 |
commit | ab91ac09924f7e356e4d2b8cf40c89a3c12011bb (patch) | |
tree | 809de6479064a91d3ecd7e6e09f3dda0212b9082 /src/corelib/io/qfilesystemwatcher_win.cpp | |
parent | 605bda587e0d3b3eebb871a668ad6014cf843a10 (diff) |
Don't store iterators on QHash while erasing
QHash::erase() in the new QHash will invalidate
all iterators pointing into the hash.
Change-Id: Ia54e8485a947cd7274f832c7c8c624d0aaded4ba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemwatcher_win.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_win.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index f955e3b53a..2f0a209b76 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -697,21 +697,20 @@ void QWindowsFileSystemWatcherEngineThread::run() qErrnoWarning(error, "%ls", qUtf16Printable(msgFindNextFailed(h))); } - for (auto it = h.begin(), end = h.end(); it != end; /*erasing*/ ) { - auto x = it++; - QString absolutePath = x.value().absolutePath; - QFileInfo fileInfo(x.value().path); - DEBUG() << "checking" << x.key(); + for (auto it = h.begin(); it != h.end(); /*erasing*/ ) { + QString absolutePath = it.value().absolutePath; + QFileInfo fileInfo(it.value().path); + DEBUG() << "checking" << it.key(); // i'm not completely sure the fileInfo.exist() check will ever work... see QTBUG-2331 // ..however, I'm not completely sure enough to remove it. if (fakeRemove || !fileInfo.exists()) { - DEBUG() << x.key() << "removed!"; - if (x.value().isDir) - emit directoryChanged(x.value().path, true); + DEBUG() << it.key() << "removed!"; + if (it.value().isDir) + emit directoryChanged(it.value().path, true); else - emit fileChanged(x.value().path, true); - h.erase(x); + emit fileChanged(it.value().path, true); + it = h.erase(it); // close the notification handle if the directory has been removed if (h.isEmpty()) { @@ -726,15 +725,17 @@ void QWindowsFileSystemWatcherEngineThread::run() // h is now invalid break; } - } else if (x.value().isDir) { - DEBUG() << x.key() << "directory changed!"; - emit directoryChanged(x.value().path, false); - x.value() = fileInfo; - } else if (x.value() != fileInfo) { - DEBUG() << x.key() << "file changed!"; - emit fileChanged(x.value().path, false); - x.value() = fileInfo; + continue; + } else if (it.value().isDir) { + DEBUG() << it.key() << "directory changed!"; + emit directoryChanged(it.value().path, false); + it.value() = fileInfo; + } else if (it.value() != fileInfo) { + DEBUG() << it.key() << "file changed!"; + emit fileChanged(it.value().path, false); + it.value() = fileInfo; } + ++it; } } } else { |