aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljsast.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-06-15 09:03:53 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-06-25 20:04:05 +0000
commitd5adc61b1fe358f7ba5d3570305eaf0733426e2f (patch)
tree5f5d041a57d2c7d800acefc0ca9e5cb9b80b37d2 /src/qml/parser/qqmljsast.cpp
parentd26a497f3eaf37d6733b4ab1bceb2158eb127648 (diff)
Fix string memory leak in JavaScript AST
Commit 02252ae08d introduced a QString member in a JS memory pool class, which leaks unfortunately as the pool is not designed to call destructors of allocated types. Typically strings in the AST are derived from input and therefore a QStringRef is fine. The bindingIdentifier in the PatterElement however is sometimes synthesized, so a separate storage for dynamically allocated strings in the memory pool allows for using QStringRef again. Change-Id: I94d090df653d784c554452722b3b759031e4735b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/parser/qqmljsast.cpp')
-rw-r--r--src/qml/parser/qqmljsast.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index b338c5bbfe..1c997e1de7 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -422,7 +422,7 @@ bool PatternElement::convertLiteralToAssignmentPattern(MemoryPool *pool, SourceL
}
if (auto *i = cast<IdentifierExpression *>(lhs)) {
- bindingIdentifier = i->name.toString();
+ bindingIdentifier = i->name;
identifierToken = i->identifierToken;
return true;
}
@@ -959,7 +959,7 @@ QStringList FormalParameterList::formals() const
int i = 0;
for (const FormalParameterList *it = this; it; it = it->next) {
if (it->element) {
- QString name = it->element->bindingIdentifier;
+ QString name = it->element->bindingIdentifier.toString();
int duplicateIndex = formals.indexOf(name);
if (duplicateIndex >= 0) {
// change the name of the earlier argument to enforce the lookup semantics from the spec
@@ -993,7 +993,7 @@ void FormalParameterList::accept0(Visitor *visitor)
visitor->endVisit(this);
}
-FormalParameterList *FormalParameterList::finish()
+FormalParameterList *FormalParameterList::finish(QQmlJS::MemoryPool *pool)
{
FormalParameterList *front = next;
next = nullptr;
@@ -1001,7 +1001,7 @@ FormalParameterList *FormalParameterList::finish()
int i = 0;
for (const FormalParameterList *it = this; it; it = it->next) {
if (it->element && it->element->bindingIdentifier.isEmpty())
- it->element->bindingIdentifier = QLatin1String("arg#") + QString::number(i);
+ it->element->bindingIdentifier = pool->newString(QLatin1String("arg#") + QString::number(i));
++i;
}
return front;
@@ -1220,7 +1220,7 @@ void PatternElement::boundNames(QStringList *names)
else if (PatternPropertyList *p = propertyList())
p->boundNames(names);
} else {
- names->append(bindingIdentifier);
+ names->append(bindingIdentifier.toString());
}
}