diff options
author | Joerg Bornemann <joerg.bornemann@digia.com> | 2012-12-03 16:19:03 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-04 12:42:07 +0100 |
commit | 056d9b57cee7476cdb6e901334c9f8e3992f5105 (patch) | |
tree | ea6aa4a3ceb9968e6eba2c0a5140e3d66d0b0288 | |
parent | 57712fa583f22b3f6be63d98ab6bec3504e9a628 (diff) |
dumpcpp: properly clean up temporary metaobjects
All qax_* functions that return QMetaObject instances actually return
instances of QAxMetaObject. To make sure that ~QAxMetaObject is
called, we introduce the qax_deleteMetaObject function and call it in
the appropriate places.
The explicit call to QByteArray::detach is needed because the
affected QMetaObject/Method calls return a QByteArray that directly
holds a pointer to the QByteArrayData contained in QAxMetaObject.
Once the QAxMetaObject is destroyed, the QByteArray objects will hold
pointers to freed memory. Therefore we make a deep copy of the
QByteArray by detaching it.
Task-number: QTBUG-28325
Change-Id: I97613f12f1a30608dd5acd67d0faebb3f39cdf70
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r-- | src/activeqt/container/qaxbase.cpp | 5 | ||||
-rw-r--r-- | tools/dumpcpp/main.cpp | 19 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/activeqt/container/qaxbase.cpp b/src/activeqt/container/qaxbase.cpp index a212f2c..5269bba 100644 --- a/src/activeqt/container/qaxbase.cpp +++ b/src/activeqt/container/qaxbase.cpp @@ -1832,6 +1832,11 @@ QMetaObject *qax_readClassInfo(ITypeLib *typeLib, ITypeInfo *classInfo, const QM return generator.metaObject(parentObject, className.toLatin1()); } +void qax_deleteMetaObject(QMetaObject *metaObject) +{ + delete static_cast<QAxMetaObject *>(metaObject); +} + MetaObjectGenerator::MetaObjectGenerator(QAxBase *ax, QAxBasePrivate *dptr) : that(ax), d(dptr), disp(0), dispInfo(0), classInfo(0), typelib(0), iidnames(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Classes"), QSettings::NativeFormat) diff --git a/tools/dumpcpp/main.cpp b/tools/dumpcpp/main.cpp index c1553e9..8fe7818 100644 --- a/tools/dumpcpp/main.cpp +++ b/tools/dumpcpp/main.cpp @@ -77,6 +77,7 @@ extern QMetaObject *qax_readInterfaceInfo(ITypeLib *typeLib, ITypeInfo *typeInfo extern QList<QByteArray> qax_qualified_usertypes; extern QString qax_docuFromName(ITypeInfo *typeInfo, const QString &name); extern bool qax_dispatchEqualsIDispatch; +extern void qax_deleteMetaObject(QMetaObject *mo); QByteArray nameSpace; QMap<QByteArray, QByteArray> namespaceForType; @@ -535,6 +536,12 @@ void strreg(const QByteArray &s) } } +void strDetachAndRegister(QByteArray s) +{ + s.detach(); + strreg(s); +} + int stridx(const QByteArray &s) { int i = stringIndex.value(s); @@ -700,7 +707,7 @@ void generateClassImpl(QTextStream &out, const QMetaObject *mo, const QByteArray int argsCount = method.parameterCount(); combinedParameterCount += argsCount; - strreg(method.name()); + strDetachAndRegister(method.name()); QByteArray typeName = method.typeName(); if (!QtPrivate::isBuiltinType(typeName)) strreg(typeName); @@ -710,8 +717,8 @@ void generateClassImpl(QTextStream &out, const QMetaObject *mo, const QByteArray const QList<QByteArray> parameterTypes = method.parameterTypes(); for (int j = 0; j < argsCount; ++j) { if (!QtPrivate::isBuiltinType(parameterTypes.at(j))) - strreg(parameterTypes.at(j)); - strreg(parameterNames.at(j)); + strDetachAndRegister(parameterTypes.at(j)); + strDetachAndRegister(parameterNames.at(j)); } } for (int i = mo->propertyOffset(); i < allPropertyCount; ++i) { @@ -1119,7 +1126,7 @@ bool generateTypeLibrary(const QByteArray &typeLib, const QByteArray &outname, O break; } - delete metaObject; + qax_deleteMetaObject(metaObject); typeinfo->ReleaseTypeAttr(typeattr); typeinfo->Release(); } @@ -1278,7 +1285,7 @@ bool generateTypeLibrary(const QByteArray &typeLib, const QByteArray &outname, O currentTypeInfo = 0; } - delete metaObject; + qax_deleteMetaObject(metaObject); typeinfo->ReleaseTypeAttr(typeattr); typeinfo->Release(); @@ -1382,7 +1389,7 @@ bool generateTypeLibrary(const QByteArray &typeLib, const QByteArray &outname, O implOut << classImplBuffer << endl; } - delete namespaceObject; + qax_deleteMetaObject(namespaceObject); classesOut.flush(); inlinesOut.flush(); |