diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-03-22 09:43:16 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-03-22 12:42:32 +0000 |
commit | 90a08b0c52fbe20ea3324f7315c04c48c95a8e61 (patch) | |
tree | a1653bd740e62053d8deb76db5a54337c612b35c /src/qml/compiler | |
parent | 93ed9213f74dcd3806b0b2bfabc9900a545a5c69 (diff) |
Fix memory "leaks" in qmlcachegen
The CompilationUnit class owns the unit data. An exception was made in
bootstrap builds, where it was up to the caller to free the memory. This
lead to cases in qmlcachegen where we didn't free the memory. This is
best fixed by unifying the behavior.
This fixes the build when using an ASAN enabled build, as the runtime
aborts after calling qmlcachegen due to "leaks".
Change-Id: I8b55b4e302a9569a1d4e09eeb488c479368b50f0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qv4compileddata.cpp | 10 | ||||
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index 7906b3572c..9ffcb81fa2 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -98,18 +98,25 @@ CompilationUnit::CompilationUnit(const Unit *unitData, const QString &fileName, setUnitData(unitData, nullptr, fileName, finalUrlString); } -#ifndef V4_BOOTSTRAP CompilationUnit::~CompilationUnit() { +#ifndef V4_BOOTSTRAP unlink(); +#endif if (data) { if (data->qmlUnit() != qmlData) free(const_cast<QmlUnit *>(qmlData)); qmlData = nullptr; +#ifndef V4_BOOTSTRAP if (!(data->flags & QV4::CompiledData::Unit::StaticData)) free(const_cast<Unit *>(data)); +#else + // Unconditionally free the memory. In the dev tools we create units that have + // the flag set and will be saved to disk, so intended to persist later. + free(const_cast<Unit *>(data)); +#endif } data = nullptr; #if Q_BYTE_ORDER == Q_BIG_ENDIAN @@ -120,6 +127,7 @@ CompilationUnit::~CompilationUnit() delete [] imports; imports = nullptr; } +#ifndef V4_BOOTSTRAP QString CompilationUnit::localCacheFilePath(const QUrl &url) { diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 1341c91e97..3fd9fdf74b 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -1079,11 +1079,7 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit final : public CompilationUnitBase const QmlUnit *qmlData = nullptr; public: CompilationUnit(const Unit *unitData = nullptr, const QString &fileName = QString(), const QString &finalUrlString = QString()); -#ifdef V4_BOOTSTRAP - ~CompilationUnit() {} -#else ~CompilationUnit(); -#endif void addref() { |