From 7bd5d93899ca6c2175d6937f2011428c654bff02 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 31 Jan 2018 15:41:58 +0100 Subject: Fix memory leak with QtQuick compiler generated files When for the QQC code path we do QML type re-compilation, we allocate a new QV4::CompiledData::Unit. We must make sure that this dynamically allocated memory is released in QV4::CompiledData::CompilationUnit's destructor, by ensuring that the StaticData flag is not set. This isn't directly applicable to the ahead-of-time generated cache file unit data as they will always be re-generated (and thus the unsetting of StaticData at the end of createCompilationUnit::createUnitData()), but I've added a test-case nevertheless to ensure the correct engine behavior. Change-Id: I16973d7989567892bf8bf9dd6214bf293055d260 Reviewed-by: Lars Knoll --- src/qml/compiler/qqmlirbuilder.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/qml/compiler') diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 9749324060..e82fe71934 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1397,6 +1397,9 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output, const QV4: QV4::CompiledData::Unit *qmlUnit = reinterpret_cast(data); qmlUnit->unitSize = totalSize; qmlUnit->flags |= QV4::CompiledData::Unit::IsQml; + // This unit's memory was allocated with malloc on the heap, so it's + // definitely not suitable for StaticData access. + qmlUnit->flags &= ~QV4::CompiledData::Unit::StaticData; qmlUnit->offsetToImports = unitSize; qmlUnit->nImports = output.imports.count(); qmlUnit->offsetToObjects = unitSize + importSize; -- cgit v1.2.3