From 674992d07c3efaf7da7797e4b4a2a8e0b98b1813 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 24 Mar 2020 18:17:33 +0100 Subject: tst_qqmllanguage: Don't leak malloc()'d unit data When intrusively playing with compilation units, we need to play by the rules and actually free them when we are done. Task-number: QTBUG-82768 Change-Id: I75ac0d01d48922a6a214df0c9d2345e27fb39bff Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp') diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 6abcf13b5f..3a4fba8002 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -2471,12 +2471,16 @@ void tst_qqmllanguage::scriptStringWithoutSourceCode() QQmlRefPointer td = eng->typeLoader.getType(url); Q_ASSERT(td); - const QV4::CompiledData::Unit *readOnlyQmlUnit = td->compilationUnit()->unitData(); + QQmlRefPointer compilationUnit = td->compilationUnit(); + const QV4::CompiledData::Unit *readOnlyQmlUnit = compilationUnit->unitData(); Q_ASSERT(readOnlyQmlUnit); QV4::CompiledData::Unit *qmlUnit = reinterpret_cast(malloc(readOnlyQmlUnit->unitSize)); memcpy(qmlUnit, readOnlyQmlUnit, readOnlyQmlUnit->unitSize); + + if (!(readOnlyQmlUnit->flags & QV4::CompiledData::Unit::StaticData)) + free(const_cast(readOnlyQmlUnit)); + qmlUnit->flags &= ~QV4::CompiledData::Unit::StaticData; - QQmlRefPointer compilationUnit = td->compilationUnit(); compilationUnit->setUnitData(qmlUnit); const QV4::CompiledData::Object *rootObject = compilationUnit->objectAt(/*root object*/0); -- cgit v1.2.3