mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-17 14:00:36 -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()
|
||||
{
|
||||
s_uuidMap.remove(m_uuid);
|
||||
|
||||
if (m_modified) {
|
||||
emit databaseDiscarded();
|
||||
}
|
||||
releaseData();
|
||||
}
|
||||
|
||||
QUuid Database::uuid() const
|
||||
|
@ -378,6 +374,42 @@ bool Database::import(const QString& xmlExportPath, QString* error)
|
|||
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
|
||||
* backups are named <filename>.old.<extension>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue