From 6dac2e7df7fbf0f29667bf92b4e72426db47dbe9 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Sat, 13 Apr 2019 00:31:06 +0200 Subject: Only create the imports array if importCount is greater than 0 Since it is possible that CompilationUnit::instantiate() might be called more than once when the importCount is 0 then it should only create the imports array when it is greater than 0. This prevents a memory leak due to the recreation of this array each time it is called even though there is no imports to assign. Change-Id: I5d84b01de10bff2ca25248251e8337839e434bd5 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compileddata.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/qml/compiler/qv4compileddata.cpp') diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index 9ffcb81fa2..8f2f4a11c1 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -470,8 +470,10 @@ Heap::Module *CompilationUnit::instantiate(ExecutionEngine *engine) ScopedString importName(scope); const uint importCount = data->importEntryTableSize; - imports = new const Value *[importCount]; - memset(imports, 0, importCount * sizeof(Value *)); + if (importCount > 0) { + imports = new const Value *[importCount]; + memset(imports, 0, importCount * sizeof(Value *)); + } for (uint i = 0; i < importCount; ++i) { const CompiledData::ImportEntry &entry = data->importEntryTable()[i]; auto dependentModuleUnit = engine->loadModule(QUrl(stringAt(entry.moduleRequest)), this); -- cgit v1.2.3 From 5fcc9906d7b6d19ea3d79ccf0d6446d01b583973 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 12 Oct 2018 10:47:51 +0200 Subject: QML: Check for (valid) compilation units while hashing When an error occurred while creating a compilation unit, the pointer might be set to null. Subsequent use in hashing should check for this, and not use a nullptr. Change-Id: I62650917a740c9c1be29608285670153bed8703c Reviewed-by: Ulf Hermann --- src/qml/compiler/qv4compileddata.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/qml/compiler/qv4compileddata.cpp') diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index 8f2f4a11c1..9fb91e9140 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -897,6 +897,8 @@ bool ResolvedTypeReference::addToHash(QCryptographicHash *hash, QQmlEngine *engi hash->addData(createPropertyCache(engine)->checksum(&ok)); return ok; } + if (!compilationUnit) + return false; hash->addData(compilationUnit->unitData()->md5Checksum, sizeof(compilationUnit->unitData()->md5Checksum)); return true; } -- cgit v1.2.3