[pim/kleopatra] 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 8d1e8f46654a1c05e62447c62068e5b49d96e879 by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 27/07/2026 at 13:58.
Pushed by kloecker into branch 'master'.

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

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

https://invent.kde.org/pim/kleopatra/-/commit/8d1e8f46654a1c05e62447c62068e5b49d96e879

diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
index eb6e62ee1..f2102b17d 100644
--- a/src/crypto/gui/signencryptwidget.cpp
+++ b/src/crypto/gui/signencryptwidget.cpp
@@ -624,7 +624,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.