mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Make Entry::m_tmpHistoryItem a QScopedPointer (#2524)
* Make m_tmpHistoryItem a QScopedPointer Most of the time, `m_tmpHistoryItem` should be null by the time an `Entry` is destroyed. However, if a caller ever calls `beginUpdate()` without later calling `endUpdate()` -- perhaps because an exception was throw in the meantime -- it may not be null. This change avoids a memory leak in that case. Found via https://lgtm.com/projects/g/keepassxreboot/keepassxc/alerts
This commit is contained in:
parent
1af293847c
commit
bdee748a6a
@ -40,7 +40,6 @@ Entry::Entry()
|
||||
, m_attachments(new EntryAttachments(this))
|
||||
, m_autoTypeAssociations(new AutoTypeAssociations(this))
|
||||
, m_customData(new CustomData(this))
|
||||
, m_tmpHistoryItem(nullptr)
|
||||
, m_modifiedSinceBegin(false)
|
||||
, m_updateTimeinfo(true)
|
||||
{
|
||||
@ -706,9 +705,9 @@ void Entry::copyDataFrom(const Entry* other)
|
||||
|
||||
void Entry::beginUpdate()
|
||||
{
|
||||
Q_ASSERT(!m_tmpHistoryItem);
|
||||
Q_ASSERT(m_tmpHistoryItem.isNull());
|
||||
|
||||
m_tmpHistoryItem = new Entry();
|
||||
m_tmpHistoryItem.reset(new Entry());
|
||||
m_tmpHistoryItem->setUpdateTimeinfo(false);
|
||||
m_tmpHistoryItem->m_uuid = m_uuid;
|
||||
m_tmpHistoryItem->m_data = m_data;
|
||||
@ -721,16 +720,14 @@ void Entry::beginUpdate()
|
||||
|
||||
bool Entry::endUpdate()
|
||||
{
|
||||
Q_ASSERT(m_tmpHistoryItem);
|
||||
Q_ASSERT(!m_tmpHistoryItem.isNull());
|
||||
if (m_modifiedSinceBegin) {
|
||||
m_tmpHistoryItem->setUpdateTimeinfo(true);
|
||||
addHistoryItem(m_tmpHistoryItem);
|
||||
addHistoryItem(m_tmpHistoryItem.take());
|
||||
truncateHistory();
|
||||
} else {
|
||||
delete m_tmpHistoryItem;
|
||||
}
|
||||
|
||||
m_tmpHistoryItem = nullptr;
|
||||
m_tmpHistoryItem.reset();
|
||||
|
||||
return m_modifiedSinceBegin;
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ private:
|
||||
QPointer<CustomData> m_customData;
|
||||
QList<Entry*> m_history; // Items sorted from oldest to newest
|
||||
|
||||
Entry* m_tmpHistoryItem;
|
||||
QScopedPointer<Entry> m_tmpHistoryItem;
|
||||
bool m_modifiedSinceBegin;
|
||||
QPointer<Group> m_group;
|
||||
bool m_updateTimeinfo;
|
||||
|
Loading…
Reference in New Issue
Block a user