Commit c400a872 authored by David Jarvie's avatar David Jarvie
Browse files

Fix memory leak in destructor

parent 89fc85e8
......@@ -97,7 +97,7 @@ FileResourceDataModel::FileResourceDataModel(QObject* parent)
connect(resources, &Resources::resourcePopulated,
this, &FileResourceDataModel::slotResourceLoaded);
connect(resources, &Resources::resourceToBeRemoved,
this, &FileResourceDataModel::slotRemoveResource);
this, &FileResourceDataModel::removeResource);
connect(resources, &Resources::eventsAdded,
this, &FileResourceDataModel::slotEventsAdded);
connect(resources, &Resources::eventUpdated,
......@@ -140,6 +140,8 @@ FileResourceDataModel::~FileResourceDataModel()
mInstance = nullptr;
mInstanceIsOurs = false;
}
while (!mResources.isEmpty())
removeResource(mResources.first());
delete Resources::instance();
}
......@@ -631,18 +633,21 @@ void FileResourceDataModel::addResource(Resource& resource)
* slotResourceSettingsChanged(Deleted) being triggered, leading to crashes when
* data from the resource's events is fetched.
*/
void FileResourceDataModel::slotRemoveResource(Resource& resource)
void FileResourceDataModel::removeResource(Resource& resource)
{
qCDebug(KALARM_LOG) << "FileResourceDataModel::slotRemoveResource" << resource.displayName();
qCDebug(KALARM_LOG) << "FileResourceDataModel::removeResource" << resource.displayName();
int row = mResources.indexOf(resource);
if (row < 0)
return;
Resource r(resource); // in case 'resource' is a reference to the copy in mResources
int count = 0;
beginRemoveRows(QModelIndex(), row, row);
mResources.removeAt(row);
mResourceNodes[Resource()].removeAt(row);
auto it = mResourceNodes.find(resource);
QVector<Node*>& resourceNodes = mResourceNodes[Resource()];
delete resourceNodes.at(row);
resourceNodes.removeAt(row);
auto it = mResourceNodes.find(r);
if (it != mResourceNodes.end())
{
count = removeResourceEvents(it.value());
......
......@@ -126,7 +126,7 @@ private Q_SLOTS:
void addResource(Resource&);
void slotResourceLoaded(Resource&);
void slotResourceSettingsChanged(Resource&, ResourceType::Changes);
void slotRemoveResource(Resource&);
void removeResource(Resource&);
void slotEventsAdded(Resource&, const QList<KAEvent>&);
void slotEventUpdated(Resource&, const KAEvent&);
bool deleteEvents(Resource&, const QList<KAEvent>&);
......
Supports Markdown
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