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_polling.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_polling.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_polling.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_polling.cpp b/src/corelib/io/qfilesystemwatcher_polling.cpp index e07b02f7c2..6920eab258 100644 --- a/src/corelib/io/qfilesystemwatcher_polling.cpp +++ b/src/corelib/io/qfilesystemwatcher_polling.cpp @@ -111,37 +111,40 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path void QPollingFileSystemWatcherEngine::timeout() { for (auto it = files.begin(), end = files.end(); it != end; /*erasing*/) { - auto x = it++; - QString path = x.key(); + QString path = it.key(); QFileInfo fi(path); if (!fi.exists()) { - files.erase(x); + it = files.erase(it); emit fileChanged(path, true); - } else if (x.value() != fi) { - x.value() = fi; + continue; + } else if (it.value() != fi) { + it.value() = fi; emit fileChanged(path, false); } + ++it; } for (auto it = directories.begin(), end = directories.end(); it != end; /*erasing*/) { - auto x = it++; - QString path = x.key(); + QString path = it.key(); QFileInfo fi(path); if (!path.endsWith(QLatin1Char('/'))) fi = QFileInfo(path + QLatin1Char('/')); if (!fi.exists()) { - directories.erase(x); + it = directories.erase(it); emit directoryChanged(path, true); - } else if (x.value() != fi) { + continue; + } else if (it.value() != fi) { fi.refresh(); if (!fi.exists()) { - directories.erase(x); + it = directories.erase(it); emit directoryChanged(path, true); + continue; } else { - x.value() = fi; + it.value() = fi; emit directoryChanged(path, false); } } + ++it; } } |