Commit aa81208b authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Fix memory leaks

parent e86af019
......@@ -107,15 +107,15 @@ void TestEditableCourseResource::unitAddAndRemoveHandling()
EditableCourseResource course(QUrl::fromLocalFile(":/courses/de.xml"), &repository);
// begin of test
Unit unit;
unit.setId("testunit");
Unit *unit = new Unit; // TODO: change to unique pointer when interface is changed to scoped pointers
unit->setId("testunit");
const int initialUnitNumber = course.unitList().count();
QCOMPARE(initialUnitNumber, 1);
QSignalSpy spyAboutToBeAdded(&course, SIGNAL(unitAboutToBeAdded(Unit*, int)));
QSignalSpy spyAdded(&course, SIGNAL(unitAdded()));
QCOMPARE(spyAboutToBeAdded.count(), 0);
QCOMPARE(spyAdded.count(), 0);
course.addUnit(&unit);
course.addUnit(unit);
QCOMPARE(course.unitList().count(), initialUnitNumber + 1);
QCOMPARE(spyAboutToBeAdded.count(), 1);
QCOMPARE(spyAdded.count(), 1);
......
......@@ -44,6 +44,17 @@ ContributorRepository::ContributorRepository(QObject *parent)
loadLanguageResources();
}
ContributorRepository::~ContributorRepository()
{
for (auto skeleton : m_skeletonResources) {
skeleton->deleteLater();
}
m_skeletonResources.clear();
for (auto language : m_languageResources) {
language->deleteLater();
}
}
void ContributorRepository::loadLanguageResources()
{
// load language resources
......
......@@ -52,7 +52,7 @@ class ARTIKULATECORE_EXPORT ContributorRepository : public IEditableRepository
public:
explicit ContributorRepository(QObject *parent = nullptr);
~ContributorRepository() override = default;
~ContributorRepository() override;
/**
* save all changes to course resources
......
......@@ -28,6 +28,14 @@ PhonemeGroup::PhonemeGroup(QObject *parent)
{
}
PhonemeGroup::~PhonemeGroup()
{
for (auto phoneme : m_phonemes) {
phoneme->deleteLater();
}
m_phonemes.clear();
}
QString PhonemeGroup::id() const
{
return m_id;
......
......@@ -40,6 +40,7 @@ class ARTIKULATECORE_EXPORT PhonemeGroup : public QObject
public:
explicit PhonemeGroup(QObject *parent = 0);
~PhonemeGroup() override;
QString id() const;
void setId(const QString &id);
QString title() const;
......
......@@ -50,6 +50,14 @@ ResourceRepository::ResourceRepository(const QUrl &storageLocation, QObject *par
}
}
ResourceRepository::~ResourceRepository()
{
for (auto language : m_languages) {
language->deleteLater();
}
m_languages.clear();
}
QString ResourceRepository::storageLocation() const
{
return m_storageLocation;
......
......@@ -48,6 +48,7 @@ class ARTIKULATECORE_EXPORT ResourceRepository : public IResourceRepository
public:
explicit ResourceRepository(QObject *parent = nullptr);
~ResourceRepository() override;
/**
* @brief Construtor for ResourceRepository object with explicitly set course folder
......
......@@ -41,6 +41,7 @@ class CourseResourcePrivate
{
public:
CourseResourcePrivate() = default;
~CourseResourcePrivate();
void loadCourse(CourseResource *parent);
......@@ -57,6 +58,14 @@ public:
bool m_courseLoaded{ false }; ///<! indicates if course was completely parsed
};
CourseResourcePrivate::~CourseResourcePrivate()
{
for (auto unit : m_units) {
unit->deleteLater();
}
m_units.clear();
}
void CourseResourcePrivate::loadCourse(CourseResource *parent)
{
if (m_courseLoaded == true) {
......
......@@ -41,6 +41,10 @@ Unit::Unit(QObject *parent)
Unit::~Unit()
{
for (auto phrase : m_phraseList) {
phrase->deleteLater();
}
m_phraseList.clear();
m_phraseSignalMapper->deleteLater();
}
......
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