diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-05-11 11:25:21 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-05-11 11:28:12 (GMT) |
commit | 60ff41273a58835466022f91d4f6eb195953c739 (patch) | |
tree | 5c351cd1cfbf87bb390365d30c1e274a428b8e18 | |
parent | 887b6074e149d5302316eb57b908c051955fa4f6 (diff) | |
download | Qt-60ff41273a58835466022f91d4f6eb195953c739.zip Qt-60ff41273a58835466022f91d4f6eb195953c739.tar.gz Qt-60ff41273a58835466022f91d4f6eb195953c739.tar.bz2 |
Don't leak memory when assigning scriptvalue to iterator
The d-pointer was not deleted as it should be.
Reviewed-by: Harald Fernengel
-rw-r--r-- | src/script/qscriptvalueiterator.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp | 33 |
2 files changed, 35 insertions, 2 deletions
diff --git a/src/script/qscriptvalueiterator.cpp b/src/script/qscriptvalueiterator.cpp index fe5ef9f..1a60632 100644 --- a/src/script/qscriptvalueiterator.cpp +++ b/src/script/qscriptvalueiterator.cpp @@ -106,6 +106,7 @@ QScriptValueIteratorPrivate::QScriptValueIteratorPrivate() */ QScriptValueIteratorPrivate::~QScriptValueIteratorPrivate() { + delete it; } /*! @@ -130,7 +131,6 @@ QScriptValueIterator::QScriptValueIterator(const QScriptValue &object) QScriptValueIterator::~QScriptValueIterator() { if (d_ptr) { - delete d_ptr->it; delete d_ptr; d_ptr = 0; } @@ -312,7 +312,7 @@ void QScriptValueIterator::remove() QScriptValueIterator& QScriptValueIterator::operator=(QScriptValue &object) { if (d_ptr) { - delete d_ptr->it; + delete d_ptr; d_ptr = 0; } QScriptValueImpl val = QScriptValuePrivate::valueOf(object); diff --git a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp index 1413b0d..257ec0b 100644 --- a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp +++ b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp @@ -68,6 +68,7 @@ private slots: void iterateString(); void iterateGetterSetter(); void iterateArgumentsObject(); + void assignObjectToIterator(); void undefinedBehavior(); }; @@ -562,5 +563,37 @@ void tst_QScriptValueIterator::undefinedBehavior() QVERIFY(it.value().isNumber()); } +void tst_QScriptValueIterator::assignObjectToIterator() +{ + QScriptEngine eng; + QScriptValue obj1 = eng.newObject(); + obj1.setProperty("foo", 123); + QScriptValue obj2 = eng.newObject(); + obj2.setProperty("bar", 456); + + QScriptValueIterator it(obj1); + QVERIFY(it.hasNext()); + it.next(); + it = obj2; + QVERIFY(it.hasNext()); + it.next(); + QCOMPARE(it.name(), QString::fromLatin1("bar")); + + it = obj1; + QVERIFY(it.hasNext()); + it.next(); + QCOMPARE(it.name(), QString::fromLatin1("foo")); + + it = obj2; + QVERIFY(it.hasNext()); + it.next(); + QCOMPARE(it.name(), QString::fromLatin1("bar")); + + it = obj2; + QVERIFY(it.hasNext()); + it.next(); + QCOMPARE(it.name(), QString::fromLatin1("bar")); +} + QTEST_MAIN(tst_QScriptValueIterator) #include "tst_qscriptvalueiterator.moc" |