Skip to content

Commit

Permalink
Deleting a running QtKeychain job can cause a crash
Browse files Browse the repository at this point in the history
Fixes: #11358
  • Loading branch information
TheOneRing committed Nov 10, 2023
1 parent 193839f commit a17f6da
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/libsync/creds/credentialmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "theme.h"

#include "common/asserts.h"
#include "common/chronoelapsedtimer.h"

#include <QCborValue>
#include <QLoggingCategory>
Expand Down Expand Up @@ -73,24 +74,18 @@ QKeychain::Job *CredentialManager::set(const QString &key, const QVariant &data)
timer->setInterval(tiemoutC);
timer->setSingleShot(true);

auto timedOut = std::make_unique<bool>(false);
connect(timer, &QTimer::timeout, writeJob, [writeJob, timedOut = timedOut.get()] {
*timedOut = true;
Q_EMIT writeJob->finished(writeJob);
writeJob->deleteLater();
Utility::ChronoElapsedTimer elapsedTimer;
connect(timer, &QTimer::timeout, writeJob, [writeJob, timer, elapsedTimer] {
qCWarning(lcCredentialsManager) << "set" << writeJob->key() << "has not finished after" << elapsedTimer.duration();
timer->deleteLater();
});
connect(writeJob, &QKeychain::WritePasswordJob::finished, this, [writeJob, timer, key, timedOut = std::move(timedOut), this] {
timer->stop();
connect(writeJob, &QKeychain::WritePasswordJob::finished, this, [writeJob, key, elapsedTimer, this] {
if (writeJob->error() == QKeychain::NoError) {
if (*timedOut.get()) {
qCInfo(lcCredentialsManager) << "set" << writeJob->key() << "timed out";
} else {
qCInfo(lcCredentialsManager) << "added" << writeJob->key();
// just a list, the values don't matter
credentialsList().setValue(key, true);
}
qCInfo(lcCredentialsManager) << "added" << writeJob->key() << "after" << elapsedTimer.duration();
// just a list, the values don't matter
credentialsList().setValue(key, true);
} else {
qCWarning(lcCredentialsManager) << "Failed to set:" << writeJob->key() << writeJob->errorString();
qCWarning(lcCredentialsManager) << "Failed to set:" << writeJob->key() << writeJob->errorString() << "after" << elapsedTimer.duration();
}
});
writeJob->setBinaryData(QCborValue::fromVariant(data).toCbor());
Expand Down

0 comments on commit a17f6da

Please sign in to comment.