mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-18 06:20:39 -04:00
Ensure database contents are released right away.
When we lock a database, we reset the database pointer to free its resources. Since various other widgets besides the DatabaseWidget hold references to the shared pointer object, however, it cannot be guaranteed that the actual database object will be freed right away. This patch adds a releaseData() method which is called upon database lock to ensure all residual data is cleared without having to rely on the actual database object being cleaned up.
This commit is contained in:
parent
87ca7c7f7b
commit
22af66e3b5
3 changed files with 43 additions and 8 deletions
|
@ -72,11 +72,7 @@ Database::Database(const QString& filePath)
|
||||||
|
|
||||||
Database::~Database()
|
Database::~Database()
|
||||||
{
|
{
|
||||||
s_uuidMap.remove(m_uuid);
|
releaseData();
|
||||||
|
|
||||||
if (m_modified) {
|
|
||||||
emit databaseDiscarded();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Database::uuid() const
|
QUuid Database::uuid() const
|
||||||
|
@ -378,6 +374,42 @@ bool Database::import(const QString& xmlExportPath, QString* error)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release all stored group, entry, and meta data of this database.
|
||||||
|
*
|
||||||
|
* Call this method to ensure all data is cleared even if valid
|
||||||
|
* pointers to this Database object are still being held.
|
||||||
|
*
|
||||||
|
* A previously reparented root group will not be freed.
|
||||||
|
*/
|
||||||
|
void Database::releaseData()
|
||||||
|
{
|
||||||
|
s_uuidMap.remove(m_uuid);
|
||||||
|
m_uuid = QUuid();
|
||||||
|
|
||||||
|
if (m_modified) {
|
||||||
|
emit databaseDiscarded();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_data = DatabaseData();
|
||||||
|
|
||||||
|
if (m_rootGroup && m_rootGroup->parent() == this) {
|
||||||
|
delete m_rootGroup;
|
||||||
|
}
|
||||||
|
if (m_metadata) {
|
||||||
|
delete m_metadata;
|
||||||
|
}
|
||||||
|
if (m_fileWatcher) {
|
||||||
|
delete m_fileWatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deletedObjects.clear();
|
||||||
|
m_commonUsernames.clear();
|
||||||
|
|
||||||
|
m_initialized = false;
|
||||||
|
m_modified = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the old backup and replace it with a new one
|
* Remove the old backup and replace it with a new one
|
||||||
* backups are named <filename>.old.<extension>
|
* backups are named <filename>.old.<extension>
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "crypto/kdf/Kdf.h"
|
#include "crypto/kdf/Kdf.h"
|
||||||
#include "format/KeePass2.h"
|
#include "format/KeePass2.h"
|
||||||
#include "keys/CompositeKey.h"
|
#include "keys/CompositeKey.h"
|
||||||
|
|
||||||
class Entry;
|
class Entry;
|
||||||
enum class EntryReferenceType;
|
enum class EntryReferenceType;
|
||||||
class FileWatcher;
|
class FileWatcher;
|
||||||
|
@ -76,6 +75,8 @@ public:
|
||||||
bool extract(QByteArray&, QString* error = nullptr);
|
bool extract(QByteArray&, QString* error = nullptr);
|
||||||
bool import(const QString& xmlExportPath, QString* error = nullptr);
|
bool import(const QString& xmlExportPath, QString* error = nullptr);
|
||||||
|
|
||||||
|
void releaseData();
|
||||||
|
|
||||||
bool isInitialized() const;
|
bool isInitialized() const;
|
||||||
void setInitialized(bool initialized);
|
void setInitialized(bool initialized);
|
||||||
bool isModified() const;
|
bool isModified() const;
|
||||||
|
@ -182,9 +183,9 @@ private:
|
||||||
bool restoreDatabase(const QString& filePath);
|
bool restoreDatabase(const QString& filePath);
|
||||||
bool performSave(const QString& filePath, QString* error, bool atomic, bool backup);
|
bool performSave(const QString& filePath, QString* error, bool atomic, bool backup);
|
||||||
|
|
||||||
Metadata* const m_metadata;
|
QPointer<Metadata> const m_metadata;
|
||||||
DatabaseData m_data;
|
DatabaseData m_data;
|
||||||
Group* m_rootGroup;
|
QPointer<Group> m_rootGroup;
|
||||||
QList<DeletedObject> m_deletedObjects;
|
QList<DeletedObject> m_deletedObjects;
|
||||||
QPointer<QTimer> m_timer;
|
QPointer<QTimer> m_timer;
|
||||||
QPointer<FileWatcher> m_fileWatcher;
|
QPointer<FileWatcher> m_fileWatcher;
|
||||||
|
|
|
@ -418,6 +418,8 @@ void DatabaseWidget::replaceDatabase(QSharedPointer<Database> db)
|
||||||
// Keep the instance active till the end of this function
|
// Keep the instance active till the end of this function
|
||||||
Q_UNUSED(oldDb);
|
Q_UNUSED(oldDb);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
oldDb->releaseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::cloneEntry()
|
void DatabaseWidget::cloneEntry()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue