Commit f60b327c authored by Ahmad Samir's avatar Ahmad Samir
Browse files

kio_filenamesearch: don't use iterators when searching pending dirs

Looking at the backtrace from the bug report, it looks like the vector
could get reallocated when it changes capacity ...etc, which would
invalidate iterators.

Instead use a FIFO std::queue, since ideally the dirs should be searched in
the same order they're added to the pendingDirs container, and then
removed, and removing from the from of a vector is more costly than with a
queue (which uses a std::deque by default).

BUG: 448114
FIXED-IN: 22.04.3
parent 0b84d54e
......@@ -152,13 +152,13 @@ void FileNameSearchProtocol::listDir(const QUrl &url)
const bool isContent = urlQuery.queryItemValue(QStringLiteral("checkContent")) == QLatin1String("yes");
std::set<QString> iteratedDirs;
std::vector<QUrl> pendingDirs;
std::queue<QUrl> pendingDirs;
searchDir(dirUrl, regex, isContent, iteratedDirs, pendingDirs);
for (auto it = pendingDirs.begin(); it != pendingDirs.end(); /* */) {
const QUrl pendingUrl = *it;
it = pendingDirs.erase(it);
while (!pendingDirs.empty()) {
const QUrl pendingUrl = pendingDirs.front();
searchDir(pendingUrl, regex, isContent, iteratedDirs, pendingDirs);
......@@ -169,7 +169,7 @@ void FileNameSearchProtocol::searchDir(const QUrl &dirUrl,
const QRegularExpression &regex,
bool searchContents,
std::set<QString> &iteratedDirs,
std::vector<QUrl> &pendingDirs)
std::queue<QUrl> &pendingDirs)
KIO::ListJob *listJob = KIO::listRecursive(dirUrl, KIO::HideProgressInfo, false /* hidden */);
......@@ -203,7 +203,7 @@ void FileNameSearchProtocol::searchDir(const QUrl &dirUrl,
if (const QString linkDest = entry.stringValue(KIO::UDSEntry::UDS_LINK_DEST); !linkDest.isEmpty()) {
// Remember the dir to prevent endless loops
if (const auto [it, isInserted] = iteratedDirs.insert(linkDest); isInserted) {
......@@ -12,7 +12,7 @@
#include <QUrl>
#include <set>
#include <vector>
#include <queue>
* @brief Lists files that match a specific search pattern.
......@@ -47,7 +47,7 @@ private:
const QRegularExpression &regex,
bool searchContents,
std::set<QString> &iteratedDirs,
std::vector<QUrl> &pendingDirs);
std::queue<QUrl> &pendingDirs);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment