Fix QtSharedPointer::ExternalRefCountData object leak in v4 engine
authorLiang Jian <jianliang79@gmail.com>
Fri, 28 Mar 2014 05:23:36 +0000 (13:23 +0800)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 28 Mar 2014 07:42:10 +0000 (08:42 +0100)
Always call ~QObjectWrapper() to the wrapper object in
QObjectWrapper::destroy(), otherwise the m_object member of QObjectWrapper
may still hold a QtSharedPointer::ExternalRefCountData object which will
never been deleted.
I don't know why this will not cause leak in the past, but it seems that
the leak was introduced in 7ae796cb141b73a1b215b2b0fd64b7ffbbd1e510

Change-Id: I24b49bb11f95b7e3060c7adba1ab80b615da2942
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4qobjectwrapper.cpp

index 67801f39b7a3d2b9ec0def83c8955e96885e67bd..f611be29659d59871c853758028b561e184dc7e2 100644 (file)
@@ -1008,7 +1008,10 @@ namespace {
 void QObjectWrapper::destroy(Managed *that)
 {
     QObjectWrapper *This = static_cast<QObjectWrapper*>(that);
-    QPointer<QObject> &object = This->m_object;
+    QPointer<QObject> object = This->m_object;
+    ExecutionEngine *engine = This->engine();
+    This->~QObjectWrapper();
+    This = 0;
     if (!object)
         return;
 
@@ -1020,9 +1023,7 @@ void QObjectWrapper::destroy(Managed *that)
         return;
 
     QObjectDeleter *deleter = new QObjectDeleter(object);
-    This->engine()->memoryManager->registerDeletable(deleter);
-
-    This->~QObjectWrapper();
+    engine->memoryManager->registerDeletable(deleter);
 }