[pim/kleopatra/release/26.08] src/crypto/gui: Avoid crash while updating widgets for unknown recipients

Ingo Klöcker <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit a25f30faed2b3416bca8f3a277b38d16195ff485 by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 27/07/2026 at 14:00.
Pushed by kloecker into branch 'release/26.08'.

Avoid crash while updating widgets for unknown recipients

We have to iterate over a copy of mUnknownWidgets because the list might
be modified during iteration.

Suggested-by: Vadim
CCBUG: 523471
(cherry picked from commit 8d1e8f46654a1c05e62447c62068e5b49d96e879)

M  +3    -1    src/crypto/gui/signencryptwidget.cpp

https://invent.kde.org/pim/kleopatra/-/commit/a25f30faed2b3416bca8f3a277b38d16195ff485

diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
index 1213e3861..57d36440e 100644
--- a/src/crypto/gui/signencryptwidget.cpp
+++ b/src/crypto/gui/signencryptwidget.cpp
@@ -643,7 +643,9 @@ void SignEncryptWidget::addUnknownRecipient(const char *keyID)
 
     connect(KeyCache::instance().get(), &Kleo::KeyCache::keysMayHaveChanged, this, [this]() {
         // Check if any unknown recipient can now be found.
-        for (auto w : std::as_const(d->mUnknownWidgets)) {
+        // Iterate over a copy because mUnknownWidgets might be modified in the loop
+        const auto unknownWidgets = d->mUnknownWidgets;
+        for (auto w : unknownWidgets) {
             auto key = KeyCache::instance()->findByKeyIDOrFingerprint(w->keyID().toLatin1().constData());
             if (key.isNull()) {
                 std::vector<std::string> subids;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.