diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-24 16:57:06 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-25 08:36:34 (GMT) |
commit | 3636e666528b72de79f8c7012690bb9e279f0863 (patch) | |
tree | ed99d1e098f059a10fdf39f0db820c2dd951098a /src/script/api | |
parent | 042f15fefd19584c546cb55f24c4c79c4d76529c (diff) | |
download | Qt-3636e666528b72de79f8c7012690bb9e279f0863.zip Qt-3636e666528b72de79f8c7012690bb9e279f0863.tar.gz Qt-3636e666528b72de79f8c7012690bb9e279f0863.tar.bz2 |
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/api')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 631175a..033d92e 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()); |