diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-01-31 15:41:58 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-02-02 05:46:20 +0000 |
commit | 7bd5d93899ca6c2175d6937f2011428c654bff02 (patch) | |
tree | fc10819f2e6d98cfaf0052d9b285f2745bd3d8c1 /src/qml/compiler/qqmlirbuilder.cpp | |
parent | f7ffed94c1540e015794a8d6d4910e8ca87c15e1 (diff) |
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 <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qqmlirbuilder.cpp')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
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<QV4::CompiledData::Unit *>(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; |