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);
m_providers.clear();
qDeleteAll(m_factories);
delete m_writer;
m_instance = nullptr;
}

View File

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

View File

@@ -220,6 +220,14 @@ DebuggerRunConfigurationAspect::DebuggerRunConfigurationAspect(Target *target)
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)
{
m_qmlAspect->setValue(value);

View File

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

View File

@@ -94,12 +94,16 @@ auto findComboBox(Utils::Wizard *wizard, const QString &objectName) {
};
} // namespace
struct FactoryDeleter { void operator()(ProjectExplorer::JsonWizardFactory *f) { f->deleteLater(); } };
using FactoryPtr = std::unique_ptr<ProjectExplorer::JsonWizardFactory, FactoryDeleter>;
void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsEmptyWizard()
{
QString errorMessage;
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);
QCOMPARE(qPrintable(errorMessage), "Page has no typeId set.");
}
@@ -110,7 +114,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsEmptyPage()
const QJsonObject pages = createFieldPageJsonObject(QJsonArray());
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);
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);
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(errorMessage.isEmpty());
}
@@ -166,7 +170,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsCheckBox()
});
const QJsonObject pages = createFieldPageJsonObject(widgets);
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));
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 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));
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 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));
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 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));
Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Core::Id(), QVariantMap());

View File

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

View File

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

View File

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

View File

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