Properly block modified signal during Database destruction (#6438)

fixes #6393
This commit is contained in:
Aetf 2021-05-27 21:50:15 -04:00 committed by GitHub
parent 66c3026cf5
commit 81a66c439c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 370 additions and 179 deletions

View file

@ -99,6 +99,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent)
, m_opVaultOpenWidget(new OpVaultOpenWidget(this))
, m_groupView(new GroupView(m_db.data(), m_mainSplitter))
, m_saveAttempts(0)
, m_entrySearcher(new EntrySearcher(false))
{
Q_ASSERT(m_db);
@ -211,7 +212,6 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent)
m_blockAutoSave = false;
m_EntrySearcher = new EntrySearcher(false);
m_searchLimitGroup = config()->get(Config::SearchLimitGroup).toBool();
#ifdef WITH_XC_KEESHARE
@ -234,7 +234,13 @@ DatabaseWidget::DatabaseWidget(const QString& filePath, QWidget* parent)
DatabaseWidget::~DatabaseWidget()
{
delete m_EntrySearcher;
// Trigger any Database deletion related signals manually by
// explicitly clearing the Database pointer, instead of leaving it to ~QSharedPointer.
// QSharedPointer may behave differently depending on whether it is cleared by the `clear` method
// or by its destructor. In the latter case, the ref counter may not be correctly maintained
// if a copy of the QSharedPointer is created in any slots activated by the Database destructor.
// More details: https://github.com/keepassxreboot/keepassxc/issues/6393.
m_db.clear();
}
QSharedPointer<Database> DatabaseWidget::database() const
@ -1061,10 +1067,10 @@ void DatabaseWidget::connectDatabaseSignals()
SIGNAL(filePathChanged(QString, QString)),
SIGNAL(databaseFilePathChanged(QString, QString)));
connect(m_db.data(), SIGNAL(databaseModified()), SIGNAL(databaseModified()));
connect(m_db.data(), SIGNAL(databaseModified()), SLOT(onDatabaseModified()));
connect(m_db.data(), SIGNAL(databaseSaved()), SIGNAL(databaseSaved()));
connect(m_db.data(), SIGNAL(databaseFileChanged()), this, SLOT(reloadDatabaseFile()));
connect(m_db.data(), &Database::modified, this, &DatabaseWidget::databaseModified);
connect(m_db.data(), &Database::modified, this, &DatabaseWidget::onDatabaseModified);
connect(m_db.data(), &Database::databaseSaved, this, &DatabaseWidget::databaseSaved);
connect(m_db.data(), &Database::databaseFileChanged, this, &DatabaseWidget::reloadDatabaseFile);
}
void DatabaseWidget::loadDatabase(bool accepted)
@ -1366,7 +1372,7 @@ void DatabaseWidget::search(const QString& searchtext)
Group* searchGroup = m_searchLimitGroup ? currentGroup() : m_db->rootGroup();
QList<Entry*> searchResult = m_EntrySearcher->search(searchtext, searchGroup);
QList<Entry*> searchResult = m_entrySearcher->search(searchtext, searchGroup);
m_entryView->displaySearch(searchResult);
m_lastSearchText = searchtext;
@ -1388,7 +1394,7 @@ void DatabaseWidget::search(const QString& searchtext)
void DatabaseWidget::setSearchCaseSensitive(bool state)
{
m_EntrySearcher->setCaseSensitive(state);
m_entrySearcher->setCaseSensitive(state);
refreshSearch();
}

View file

@ -290,7 +290,7 @@ private:
int m_saveAttempts;
// Search state
EntrySearcher* m_EntrySearcher;
QScopedPointer<EntrySearcher> m_entrySearcher;
QString m_lastSearchText;
bool m_searchLimitGroup;

View file

@ -63,7 +63,7 @@ void EditWidgetProperties::setCustomData(CustomData* customData)
m_customData = customData;
if (m_customData) {
connect(m_customData, SIGNAL(customDataModified()), SLOT(update()));
connect(m_customData, &CustomData::modified, this, &EditWidgetProperties::update);
}
update();

View file

@ -532,19 +532,23 @@ void EditEntryWidget::setupSSHAgent()
m_sshAgentUi->commentTextLabel->setFont(fixedFont);
m_sshAgentUi->publicKeyEdit->setFont(fixedFont);
connect(m_sshAgentUi->attachmentRadioButton, SIGNAL(clicked(bool)), SLOT(updateSSHAgentKeyInfo()));
connect(m_sshAgentUi->attachmentComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateSSHAgentAttachment()));
connect(m_sshAgentUi->externalFileRadioButton, SIGNAL(clicked(bool)), SLOT(updateSSHAgentKeyInfo()));
connect(m_sshAgentUi->externalFileEdit, SIGNAL(textChanged(QString)), SLOT(updateSSHAgentKeyInfo()));
connect(m_sshAgentUi->browseButton, SIGNAL(clicked()), SLOT(browsePrivateKey()));
connect(m_sshAgentUi->addToAgentButton, SIGNAL(clicked()), SLOT(addKeyToAgent()));
connect(m_sshAgentUi->removeFromAgentButton, SIGNAL(clicked()), SLOT(removeKeyFromAgent()));
connect(m_sshAgentUi->decryptButton, SIGNAL(clicked()), SLOT(decryptPrivateKey()));
connect(m_sshAgentUi->copyToClipboardButton, SIGNAL(clicked()), SLOT(copyPublicKey()));
// clang-format off
connect(m_sshAgentUi->attachmentRadioButton, &QRadioButton::clicked,
this, &EditEntryWidget::updateSSHAgentKeyInfo);
connect(m_sshAgentUi->attachmentComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &EditEntryWidget::updateSSHAgentAttachment);
connect(m_sshAgentUi->externalFileRadioButton, &QRadioButton::clicked,
this, &EditEntryWidget::updateSSHAgentKeyInfo);
connect(m_sshAgentUi->externalFileEdit, &QLineEdit::textChanged, this, &EditEntryWidget::updateSSHAgentKeyInfo);
connect(m_sshAgentUi->browseButton, &QPushButton::clicked, this, &EditEntryWidget::browsePrivateKey);
connect(m_sshAgentUi->addToAgentButton, &QPushButton::clicked, this, &EditEntryWidget::addKeyToAgent);
connect(m_sshAgentUi->removeFromAgentButton, &QPushButton::clicked, this, &EditEntryWidget::removeKeyFromAgent);
connect(m_sshAgentUi->decryptButton, &QPushButton::clicked, this, &EditEntryWidget::decryptPrivateKey);
connect(m_sshAgentUi->copyToClipboardButton, &QPushButton::clicked, this, &EditEntryWidget::copyPublicKey);
connect(m_advancedUi->attachmentsWidget->entryAttachments(),
SIGNAL(entryAttachmentsModified()),
SLOT(updateSSHAgentAttachments()));
connect(m_advancedUi->attachmentsWidget->entryAttachments(), &EntryAttachments::modified,
this, &EditEntryWidget::updateSSHAgentAttachments);
// clang-format on
addPage(tr("SSH Agent"), icons()->icon("utilities-terminal"), m_sshAgentWidget);
}
@ -803,7 +807,7 @@ void EditEntryWidget::loadEntry(Entry* entry,
m_create = create;
m_history = history;
connect(m_entry, &Entry::entryModified, this, [this] { m_entryModifiedTimer.start(); });
connect(m_entry, &Entry::modified, this, [this] { m_entryModifiedTimer.start(); });
if (history) {
setHeadline(QString("%1 \u2022 %2").arg(parentName, tr("Entry history")));

View file

@ -124,7 +124,7 @@ void EditGroupWidget::loadGroup(Group* group, bool create, const QSharedPointer<
m_db = database;
m_temporaryGroup.reset(group->clone(Entry::CloneNoFlags, Group::CloneNoFlags));
connect(m_temporaryGroup->customData(), SIGNAL(customDataModified()), SLOT(setModified()));
connect(m_temporaryGroup->customData(), &CustomData::modified, this, [this]() { setModified(true); });
if (create) {
setHeadline(tr("Add group"));