Skip to content

Commit 64227d0

Browse files
committed
Fix a concurrency related crash in the socket api
1 parent 6ce2948 commit 64227d0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

changelog/unreleased/8664

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: We fixed a potential crash in the socket api
2+
3+
We fixed a potential concurrency related crash in the socket api.
4+
5+
https://github.com/owncloud/client/pull/8664

src/gui/socketapi/socketapi.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,7 @@ void SocketApi::slotRegisterPath(const QString &alias)
432432

433433
Folder *f = FolderMan::instance()->folder(alias);
434434
if (f) {
435-
const QString message = buildRegisterPathMessage(removeTrailingSlash(f->path()));
436-
for (const auto &listener : qAsConst(_listeners)) {
437-
listener->sendMessage(message);
438-
}
435+
broadcastMessage(buildRegisterPathMessage(removeTrailingSlash(f->path())));
439436
}
440437

441438
_registeredAliases.insert(alias);
@@ -479,7 +476,9 @@ void SocketApi::slotUpdateFolderView(Folder *f)
479476

480477
void SocketApi::broadcastMessage(const QString &msg, bool doWait)
481478
{
482-
for (const auto &listener : qAsConst(_listeners)) {
479+
// operate on a copy of the list to prevent concurrency issues
480+
const auto clients = _listeners.values();
481+
for (const auto &listener : clients) {
483482
listener->sendMessage(msg, doWait);
484483
}
485484
}
@@ -530,7 +529,9 @@ void SocketApi::broadcastStatusPushMessage(const QString &systemPath, SyncFileSt
530529
QString msg = buildMessage(QLatin1String("STATUS"), systemPath, fileStatus.toSocketAPIString());
531530
Q_ASSERT(!systemPath.endsWith('/'));
532531
uint directoryHash = qHash(systemPath.left(systemPath.lastIndexOf('/')));
533-
for (const auto &listener : qAsConst(_listeners)) {
532+
// operate on a copy of the list to prevent concurrency issues
533+
const auto clients = _listeners.values();
534+
for (const auto &listener : clients) {
534535
listener->sendMessageIfDirectoryMonitored(msg, directoryHash);
535536
}
536537
}

0 commit comments

Comments
 (0)