Fix some memory leaks

Found by Address Sanitizer.

Change-Id: I989da71e24d737e36a88b83a1f382ce2d67e3307
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-10-17 17:58:22 +02:00
parent fdca8f6265
commit 40f02011b0
9 changed files with 39 additions and 8 deletions

View File

@@ -77,6 +77,7 @@ GdbServerProviderManager::~GdbServerProviderManager()
{ {
qDeleteAll(m_providers); qDeleteAll(m_providers);
m_providers.clear(); m_providers.clear();
qDeleteAll(m_factories);
delete m_writer; delete m_writer;
m_instance = nullptr; m_instance = nullptr;
} }

View File

@@ -131,6 +131,7 @@ class DebuggerMainWindowPrivate : public QObject
{ {
public: public:
DebuggerMainWindowPrivate(DebuggerMainWindow *parent); DebuggerMainWindowPrivate(DebuggerMainWindow *parent);
~DebuggerMainWindowPrivate();
void selectPerspective(Perspective *perspective); void selectPerspective(Perspective *perspective);
void depopulateCurrentPerspective(); void depopulateCurrentPerspective();
@@ -256,6 +257,11 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent)
}); });
} }
DebuggerMainWindowPrivate::~DebuggerMainWindowPrivate()
{
delete m_editorPlaceHolder;
}
DebuggerMainWindow::DebuggerMainWindow() DebuggerMainWindow::DebuggerMainWindow()
: d(new DebuggerMainWindowPrivate(this)) : d(new DebuggerMainWindowPrivate(this))
{ {

View File

@@ -220,6 +220,14 @@ DebuggerRunConfigurationAspect::DebuggerRunConfigurationAspect(Target *target)
m_overrideStartupAspect->setLabelText(tr("Additional startup commands:")); m_overrideStartupAspect->setLabelText(tr("Additional startup commands:"));
} }
DebuggerRunConfigurationAspect::~DebuggerRunConfigurationAspect()
{
delete m_cppAspect;
delete m_qmlAspect;
delete m_multiProcessAspect;
delete m_overrideStartupAspect;
}
void DebuggerRunConfigurationAspect::setUseQmlDebugger(bool value) void DebuggerRunConfigurationAspect::setUseQmlDebugger(bool value)
{ {
m_qmlAspect->setValue(value); m_qmlAspect->setValue(value);

View File

@@ -42,6 +42,7 @@ class DEBUGGER_EXPORT DebuggerRunConfigurationAspect
public: public:
DebuggerRunConfigurationAspect(ProjectExplorer::Target *target); DebuggerRunConfigurationAspect(ProjectExplorer::Target *target);
~DebuggerRunConfigurationAspect();
void fromMap(const QVariantMap &map) override; void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override; void toMap(QVariantMap &map) const override;

View File

@@ -94,12 +94,16 @@ auto findComboBox(Utils::Wizard *wizard, const QString &objectName) {
}; };
} // namespace } // namespace
struct FactoryDeleter { void operator()(ProjectExplorer::JsonWizardFactory *f) { f->deleteLater(); } };
using FactoryPtr = std::unique_ptr<ProjectExplorer::JsonWizardFactory, FactoryDeleter>;
void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsEmptyWizard() void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsEmptyWizard()
{ {
QString errorMessage; QString errorMessage;
const QJsonObject wizard = createGeneralWizard(QJsonObject()); const QJsonObject wizard = createGeneralWizard(QJsonObject());
JsonWizardFactory *factory = ProjectExplorer::JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage); const FactoryPtr factory(ProjectExplorer::JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage));
QVERIFY(factory == nullptr); QVERIFY(factory == nullptr);
QCOMPARE(qPrintable(errorMessage), "Page has no typeId set."); QCOMPARE(qPrintable(errorMessage), "Page has no typeId set.");
} }
@@ -110,7 +114,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsEmptyPage()
const QJsonObject pages = createFieldPageJsonObject(QJsonArray()); const QJsonObject pages = createFieldPageJsonObject(QJsonArray());
const QJsonObject wizard = createGeneralWizard(pages); const QJsonObject wizard = createGeneralWizard(pages);
JsonWizardFactory *factory = ProjectExplorer::JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage));
QVERIFY(factory == nullptr); QVERIFY(factory == nullptr);
QCOMPARE(qPrintable(errorMessage), "When parsing fields of page \"PE.Wizard.Page.Fields\": "); QCOMPARE(qPrintable(errorMessage), "When parsing fields of page \"PE.Wizard.Page.Fields\": ");
} }
@@ -143,7 +147,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsUnusedKeyAtFields()
const QJsonObject wizard = createGeneralWizard(pages); const QJsonObject wizard = createGeneralWizard(pages);
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("has unsupported keys: wrong")); QTest::ignoreMessage(QtWarningMsg, QRegularExpression("has unsupported keys: wrong"));
JsonWizardFactory *factory = ProjectExplorer::JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizard.toVariantMap(), QDir(), &errorMessage));
QVERIFY(factory); QVERIFY(factory);
QVERIFY(errorMessage.isEmpty()); QVERIFY(errorMessage.isEmpty());
} }
@@ -166,7 +170,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsCheckBox()
}); });
const QJsonObject pages = createFieldPageJsonObject(widgets); const QJsonObject pages = createFieldPageJsonObject(widgets);
const QJsonObject wizardObject = createGeneralWizard(pages); const QJsonObject wizardObject = createGeneralWizard(pages);
JsonWizardFactory *factory = ProjectExplorer::JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap()); Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap());
@@ -198,7 +202,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsLineEdit()
}); });
const QJsonObject pages = createFieldPageJsonObject(widgets); const QJsonObject pages = createFieldPageJsonObject(widgets);
const QJsonObject wizardObject = createGeneralWizard(pages); const QJsonObject wizardObject = createGeneralWizard(pages);
JsonWizardFactory *factory = ProjectExplorer::JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap()); Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap());
@@ -227,7 +231,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsComboBox()
const QJsonObject pages = createFieldPageJsonObject(widgets); const QJsonObject pages = createFieldPageJsonObject(widgets);
const QJsonObject wizardObject = createGeneralWizard(pages); const QJsonObject wizardObject = createGeneralWizard(pages);
JsonWizardFactory *factory = ProjectExplorer::JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap()); Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap());
@@ -285,7 +289,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsIconList()
const QJsonObject pages = createFieldPageJsonObject(widgets); const QJsonObject pages = createFieldPageJsonObject(widgets);
const QJsonObject wizardObject = createGeneralWizard(pages); const QJsonObject wizardObject = createGeneralWizard(pages);
JsonWizardFactory *factory = ProjectExplorer::JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap()); Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap());

View File

@@ -639,6 +639,10 @@ ProjectExplorerPlugin::~ProjectExplorerPlugin()
delete dd; delete dd;
dd = nullptr; dd = nullptr;
m_instance = nullptr; m_instance = nullptr;
#ifdef WITH_TESTS
deleteTestToolchains();
#endif
} }
ProjectExplorerPlugin *ProjectExplorerPlugin::instance() ProjectExplorerPlugin *ProjectExplorerPlugin::instance()

View File

@@ -243,6 +243,7 @@ private slots:
void testToolChainMerging_data(); void testToolChainMerging_data();
void testToolChainMerging(); void testToolChainMerging();
void deleteTestToolchains();
void testUserFileAccessor_prepareToReadSettings(); void testUserFileAccessor_prepareToReadSettings();
void testUserFileAccessor_prepareToReadSettingsObsoleteVersion(); void testUserFileAccessor_prepareToReadSettingsObsoleteVersion();

View File

@@ -241,6 +241,7 @@ TargetSetupPage::~TargetSetupPage()
{ {
disconnect(); disconnect();
reset(); reset();
delete m_spacer;
delete m_ui; delete m_ui;
} }

View File

@@ -309,7 +309,7 @@ public:
setTypeDisplayName("Test Tool Chain"); setTypeDisplayName("Test Tool Chain");
} }
static QList<TTC *> toolChains(); static QList<TTC *> toolChains() { return m_toolChains; }
static bool hasToolChains() { return !m_toolChains.isEmpty(); } static bool hasToolChains() { return !m_toolChains.isEmpty(); }
Abi targetAbi() const override { return Abi::hostAbi(); } Abi targetAbi() const override { return Abi::hostAbi(); }
@@ -507,6 +507,11 @@ void ProjectExplorerPlugin::testToolChainMerging()
Utils::toSet(ops.toRegister + ops.toDemote + ops.toDelete)); Utils::toSet(ops.toRegister + ops.toDemote + ops.toDelete));
} }
void ProjectExplorerPlugin::deleteTestToolchains()
{
qDeleteAll(TTC::toolChains());
}
} // namespace ProjectExplorer } // namespace ProjectExplorer
#endif // WITH_TESTS #endif // WITH_TESTS