diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-24 18:57:06 +0200 |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-25 10:36:34 +0200 |
commit | 3636e666528b72de79f8c7012690bb9e279f0863 (patch) | |
tree | ed99d1e098f059a10fdf39f0db820c2dd951098a /src/script | |
parent | 042f15fefd19584c546cb55f24c4c79c4d76529c (diff) | |
download | qt4-tools-3636e666528b72de79f8c7012690bb9e279f0863.tar.gz |
Fix memory leak in QScriptEngine::newQObject
Do not reset the delegate and the prototype when reusing existing
wrapper.
Reviewed-by: Kent Hansen
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 14 | ||||
-rw-r--r-- | src/script/bridge/qscriptobject.cpp | 2 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 631175ac0b..033d92e993 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1180,14 +1180,14 @@ JSC::JSValue QScriptEnginePrivate::newQObject( bool preferExisting = (options & QScriptEngine::PreferExistingWrapperObject) != 0; QScriptEngine::QObjectWrapOptions opt = options & ~QScriptEngine::PreferExistingWrapperObject; QScriptObject *result = 0; - if (preferExisting) + if (preferExisting) { result = data->findWrapper(ownership, opt); - if (!result) { - result = new (exec) QScriptObject(qobjectWrapperObjectStructure); - if (preferExisting) - data->registerWrapper(result, ownership, opt); + if (result) + return result; } - Q_ASSERT(result != 0); + result = new (exec) QScriptObject(qobjectWrapperObjectStructure); + if (preferExisting) + data->registerWrapper(result, ownership, opt); result->setDelegate(new QScript::QObjectDelegate(object, ownership, options)); /*if (setDefaultPrototype)*/ { const QMetaObject *meta = object->metaObject(); @@ -1635,7 +1635,6 @@ QScriptValue QScriptEngine::newVariant(const QScriptValue &object, } QScriptObject *jscScriptObject = static_cast<QScriptObject*>(jscObject); if (!object.isVariant()) { - delete jscScriptObject->delegate(); jscScriptObject->setDelegate(new QScript::QVariantDelegate(value)); } else { QScriptValuePrivate::get(object)->setVariantValue(value); @@ -1713,7 +1712,6 @@ QScriptValue QScriptEngine::newQObject(const QScriptValue &scriptObject, } QScriptObject *jscScriptObject = static_cast<QScriptObject*>(jscObject); if (!scriptObject.isQObject()) { - delete jscScriptObject->delegate(); jscScriptObject->setDelegate(new QScript::QObjectDelegate(qtObject, ownership, options)); } else { QScript::QObjectDelegate *delegate = static_cast<QScript::QObjectDelegate*>(jscScriptObject->delegate()); diff --git a/src/script/bridge/qscriptobject.cpp b/src/script/bridge/qscriptobject.cpp index 2022baf080..e59c542e84 100644 --- a/src/script/bridge/qscriptobject.cpp +++ b/src/script/bridge/qscriptobject.cpp @@ -95,6 +95,8 @@ void QScriptObject::setDelegate(QScriptObjectDelegate *delegate) { if (!d) d = new Data(); + else + delete d->delegate; d->delegate = delegate; } |