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/jsruntime/qv4scopedvalue_p.h | |
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/jsruntime/qv4scopedvalue_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index 34fb05835f..deb52c3605 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -658,6 +658,18 @@ inline ValueRef &ValueRef::operator=(const ScopedValue &o) return *this; } +struct ScopedProperty +{ + ScopedProperty(Scope &scope) + { + property = reinterpret_cast<Property*>(scope.alloc(sizeof(Property) / sizeof(Value))); + } + + Property *operator->() { return property; } + operator const Property &() { return *property; } + + Property *property; +}; } |