[Qt-interest] Memory leak converting QScriptValue to QVariant
Alberto Scarpa
scarpa.alberto at gmail.com
Wed Aug 19 11:34:23 CEST 2009
Hi all,
I found a memory leak on Qt converting QScriptValue to QVariant.
To reproduce it:
1. Create a QScriptEngine
2. Add an object (SimpleObject) with a QVariant Q_PROPERTY (simpleObjectProperty) to the QScriptEngine
3. Set the value of this property via javascript
The javascript code is: while(1) { simpleObject.simpleObjectProperty = 1; }
The leak rises converting the QScriptValue to QVariant inseide the variantFromValue function.
A QVariant with type -1 is created and in its destructor hadle->clear(&d); is not called (see the following backtrace).
You have the leak with this simple program too:
#include <QVariant>
int main(int argc, char *argv[])
{
while(1)
QVariant v1( -1, (void*)0 );
}
Any one has a fix?
In attach at this email there is a small test application.
To test:
1. unpack & qmake & make
2. valgrind --leak-check=full ./TestLeak
79,992 bytes in 9,999 blocks are definitely lost in loss record 19 of 19
at 0x4025D2E: operator new(unsigned int) (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
by 0x426F67F: construct(QVariant::Private*, void const*) (qvariant.cpp:193)
by 0x4268FAC: QVariant::create(int, void const*) (qvariant.cpp:1343)
by 0x4269193: QVariant::QVariant(int, void const*) (qvariant.cpp:1608)
by 0x40D7734: QScript::variantFromValue(QScriptEnginePrivate*, int, QScriptValueImpl const&) (qscriptextqobject.cpp:140)
by 0x40D7C43: QScript::QtPropertyFunction::execute(QScriptContextPrivate*) (qscriptextqobject.cpp:1812)
by 0x4091514: QScriptEnginePrivate::call(QScriptValueImpl const&, QScriptValueImpl const&, QList<QScriptValueImpl>
const&, bool) (qscriptengine_p.cpp:1257)
by 0x4050FD5: QScriptValueImpl::call(QScriptValueImpl const&, QList<QScriptValueImpl> const&) (qscriptvalueimpl_p.h:724)
by 0x407CADD: QScriptContextPrivate::execute(QScript::Code*) (qscriptcontext_p.cpp:1198)
by 0x40A46A3: QScript::EvalFunction::evaluate(QScriptContextPrivate*, QString const&, int, QString const&, bool)
(qscriptengine_p.cpp:366)
by 0x409598A: QScriptEnginePrivate::evaluate(QScriptContextPrivate*, QString const&, int, QString const&)
(qscriptengine_p.cpp:938)
by 0x408BF1E: QScriptEngine::evaluate(QString const&, QString const&, int) (qscriptengine.cpp:944)
Best regards
Alberto Scarpa
Senior Software Engineer
M31 SpA
www.m31.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QVariant_Leak.tar.gz
Type: application/x-tgz
Size: 2008 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090819/6b053bcb/attachment.bin
More information about the Qt-interest-old
mailing list