aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2023-01-13 15:00:56 +0100
committerUlf Hermann <[email protected]>2023-01-16 09:49:17 +0100
commit7b0b09d87c36dfc67f0488d1ad87d720f721dea4 (patch)
tree0d23b51c4aef4b0bbc3b0dc26a34cf5e5f754392
parentaae67e762d406210d3e847bbc510677c00bcc78f (diff)
qmlls, qmllint: Avoid memory leaks
Pick-to: 6.5 Fixes: QTBUG-104643 Change-Id: I5ca0fea2ef6f822b70c08bc6e49f0d07a732b299 Reviewed-by: Sami Shalayel <[email protected]>
-rw-r--r--src/qmlcompiler/qqmljslinter.cpp25
-rw-r--r--src/qmlcompiler/qqmljslinter_p.h2
-rw-r--r--tools/qmlls/qmllanguageservertool.cpp12
3 files changed, 19 insertions, 20 deletions
diff --git a/src/qmlcompiler/qqmljslinter.cpp b/src/qmlcompiler/qqmljslinter.cpp
index fe4a8a9acf..e84b04b713 100644
--- a/src/qmlcompiler/qqmljslinter.cpp
+++ b/src/qmlcompiler/qqmljslinter.cpp
@@ -74,20 +74,19 @@ QQmlJSLinter::QQmlJSLinter(const QStringList &importPaths, const QStringList &pl
}
QQmlJSLinter::Plugin::Plugin(QQmlJSLinter::Plugin &&plugin) noexcept
+ : m_name(std::move(plugin.m_name))
+ , m_description(std::move(plugin.m_description))
+ , m_version(std::move(plugin.m_version))
+ , m_author(std::move(plugin.m_author))
+ , m_categories(std::move(plugin.m_categories))
+ , m_instance(std::move(plugin.m_instance))
+ , m_loader(std::move(plugin.m_loader))
+ , m_isBuiltin(std::move(plugin.m_isBuiltin))
+ , m_isInternal(std::move(plugin.m_isInternal))
+ , m_isValid(std::move(plugin.m_isValid))
{
- m_name = plugin.m_name;
- m_author = plugin.m_author;
- m_description = plugin.m_description;
- m_version = plugin.m_version;
- m_instance = plugin.m_instance;
- m_loader = plugin.m_loader;
- m_isValid = plugin.m_isValid;
- m_isBuiltin = plugin.m_isBuiltin;
- m_isInternal = plugin.m_isInternal;
- m_categories = plugin.m_categories;
-
// Mark the old Plugin as invalid and make sure it doesn't delete the loader
- plugin.m_loader = nullptr;
+ Q_ASSERT(!plugin.m_loader);
plugin.m_instance = nullptr;
plugin.m_isValid = false;
}
@@ -95,7 +94,7 @@ QQmlJSLinter::Plugin::Plugin(QQmlJSLinter::Plugin &&plugin) noexcept
#if QT_CONFIG(library)
QQmlJSLinter::Plugin::Plugin(QString path)
{
- m_loader = new QPluginLoader(path);
+ m_loader = std::make_unique<QPluginLoader>(path);
if (!parseMetaData(m_loader->metaData(), path))
return;
diff --git a/src/qmlcompiler/qqmljslinter_p.h b/src/qmlcompiler/qqmljslinter_p.h
index ba2a1dfdb8..c174584b34 100644
--- a/src/qmlcompiler/qqmljslinter_p.h
+++ b/src/qmlcompiler/qqmljslinter_p.h
@@ -97,7 +97,7 @@ public:
QList<QQmlJSLogger::Category> m_categories;
QQmlSA::LintPlugin *m_instance;
- QPluginLoader *m_loader = nullptr;
+ std::unique_ptr<QPluginLoader> m_loader;
bool m_isBuiltin;
bool m_isInternal =
false; // Internal plugins are those developed and maintained inside the Qt project
diff --git a/tools/qmlls/qmllanguageservertool.cpp b/tools/qmlls/qmllanguageservertool.cpp
index ee49706adc..896e0c049c 100644
--- a/tools/qmlls/qmllanguageservertool.cpp
+++ b/tools/qmlls/qmllanguageservertool.cpp
@@ -214,16 +214,16 @@ int main(int argv, char *argc[])
(parser.isSet(ignoreSettings) ? nullptr : &settings));
if (parser.isSet(buildDirOption))
qmlServer.codeModel()->setBuildPathsForRootUrl(QByteArray(), parser.values(buildDirOption));
- StdinReader *r = new StdinReader;
- QObject::connect(r, &StdinReader::receivedData, qmlServer.server(),
- &QLanguageServer::receiveData);
- QObject::connect(r, &StdinReader::eof, &app, []() {
- QTimer::singleShot(100, []() {
+ StdinReader r;
+ QObject::connect(&r, &StdinReader::receivedData,
+ qmlServer.server(), &QLanguageServer::receiveData);
+ QObject::connect(&r, &StdinReader::eof, &app, [&app]() {
+ QTimer::singleShot(100, &app, []() {
QCoreApplication::processEvents();
QCoreApplication::exit();
});
});
- QThreadPool::globalInstance()->start([r]() { r->run(); });
+ QThreadPool::globalInstance()->start([&r]() { r.run(); });
app.exec();
return qmlServer.returnValue();
}