diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-02-06 12:47:43 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-07 06:04:26 +0100 |
commit | 1298960aaa18217df44458312a8580a4d97b76e2 (patch) | |
tree | 19d9e0d81a1e2bd85cfb263fd7e8b8e236fc35be /src/qml/util | |
parent | edcdec4b5d23a04e727134723875ae40e0af6d1e (diff) |
Fix memory management issue with accessors
The earlier pattern of
Property p;
p.setSetter(new (mm) setterFunction);
p.setGetter(new (mm) getterFunction);
carries the risk of the second allocation garbage collecting the first one.
Consequently we need to put these values onto the JS stack, using a simple
ScopedProperty wrapper.
Change-Id: Ib29ea3b1eab95595dd6dfbb86fea282d23e3d899
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/util')
-rw-r--r-- | src/qml/util/qqmladaptormodel.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp index 8b79e33cc7..d38e5ac3df 100644 --- a/src/qml/util/qqmladaptormodel.cpp +++ b/src/qml/util/qqmladaptormodel.cpp @@ -219,6 +219,7 @@ public: QV4::Scoped<QV4::Object> proto(scope, v4->newObject()); proto->defineAccessorProperty(QStringLiteral("index"), get_index, 0); proto->defineAccessorProperty(QStringLiteral("hasModelChildren"), get_hasModelChildren, 0); + QV4::ScopedProperty p(scope); typedef QHash<QByteArray, int>::const_iterator iterator; for (iterator it = roleNames.constBegin(), end = roleNames.constEnd(); it != end; ++it) { @@ -226,9 +227,8 @@ public: const QByteArray &propertyName = it.key(); QV4::ScopedString name(scope, v4->newString(QString::fromUtf8(propertyName))); - QV4::Property p; - p.setGetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::get_property)); - p.setSetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::set_property)); + p->setGetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::get_property)); + p->setSetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::set_property)); proto->insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable); } prototype = proto; |