diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-02-20 10:36:37 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-09 14:51:22 +0000 |
commit | 92daa739ec114a0c9ae841db0459b0eff1f86cef (patch) | |
tree | fc32af2a0e4e6cff970c8b94c2859a74b8f9db11 | |
parent | 2bb382f9c276a1dc1258148c156222be3576aff5 (diff) |
QV4Engine: Avoid memory leak in toVariant conversion
We should really backport this to 5.14. Someone will hit it.
(cherry-picked from commit 78fd438f158839ffebcd52cc7974eac28489dbdd)
Change-Id: I2c713fd759ac40aaaac0c0943edb993d3e27686b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 76fefb767d..df2c46b64a 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1516,7 +1516,11 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, int return retn; #endif if (typeHint != -1) { - retn = QVariant(typeHint, QMetaType::create(typeHint)); + // the QVariant constructor will create a copy, so we have manually + // destroy the value returned by QMetaType::create + auto temp = QMetaType::create(typeHint); + retn = QVariant(typeHint, temp); + QMetaType::destroy(typeHint, temp); auto retnAsIterable = retn.value<QtMetaTypePrivate::QSequentialIterableImpl>(); if (retnAsIterable._iteratorCapabilities & QtMetaTypePrivate::ContainerIsAppendable) { auto const length = a->getLength(); |