Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b7b9e622 authored by Laurent Montel's avatar Laurent Montel 😁

Fix potential mem leak found by asan

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f3be606a900 in operator new(unsigned long) (/usr/lib64/libasan.so.5+0xed900)
    #1 0x7f3be46a4063 in Akonadi::EntityTreeModelPrivate::startFirstListJob() /compile/kde5/framework/kde/pim/akonadi/src/core/models/entitytreemodel_p.cpp:1465
    #2 0x7f3be4698a66 in Akonadi::EntityTreeModel::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) /compile/kde5/framework/build-gcc-qt5.12/kde/pim/akonadi/src/core/KF5AkonadiCore_autogen/include/moc_entitytreemodel.cpp:212
    #3 0x7f3be2677b71 in QObject::event(QEvent*) kernel/qobject.cpp:1258
    #4 0x7f3be32b3be0 in QApplicationPrivate::notify_helper(QObject*, QEvent*) kernel/qapplication.cpp:3752
parent b39e2a01
......@@ -76,8 +76,6 @@ EntityTreeModel::~EntityTreeModel()
}
}
d->m_rootNode = nullptr;
delete d_ptr;
}
......
......@@ -94,6 +94,10 @@ EntityTreeModelPrivate::EntityTreeModelPrivate(EntityTreeModel *parent)
EntityTreeModelPrivate::~EntityTreeModelPrivate()
{
if (m_needDeleteRootNode) {
delete m_rootNode;
}
m_rootNode = nullptr;
}
void EntityTreeModelPrivate::init(Monitor *monitor)
......@@ -1463,6 +1467,7 @@ void EntityTreeModelPrivate::startFirstListJob()
// Otherwise store it silently because it's not part of the usable model.
delete m_rootNode;
m_rootNode = new Node;
m_needDeleteRootNode = true;
m_rootNode->id = m_rootCollection.id();
m_rootNode->parent = -1;
m_rootNode->type = Node::Collection;
......@@ -1825,6 +1830,10 @@ void EntityTreeModelPrivate::endResetModel()
qDeleteAll(list);
}
m_childEntities.clear();
if (m_needDeleteRootNode) {
m_needDeleteRootNode = false;
delete m_rootNode;
}
m_rootNode = nullptr;
q->endResetModel();
......
......@@ -221,6 +221,7 @@ public:
Monitor *m_monitor = nullptr;
Collection m_rootCollection;
Node *m_rootNode = nullptr;
bool m_needDeleteRootNode = false;
QString m_rootCollectionDisplayName;
QStringList m_mimeTypeFilter;
MimeTypeChecker m_mimeChecker;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment