summaryrefslogtreecommitdiff
path: root/src/qdoc/clangcodeparser.cpp
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@qt.io>2021-11-05 12:30:37 +0100
committerTopi Reinio <topi.reinio@qt.io>2021-11-06 11:09:43 +0100
commit02057fc029e3d2cc1808fe712fca84ccfc074f99 (patch)
tree48dc2150566f2c25142732d57f61258d416c064b /src/qdoc/clangcodeparser.cpp
parent6ab73adf460794c6b218da4bfd67e342fe83df8b (diff)
downloadqttools-02057fc029e3d2cc1808fe712fca84ccfc074f99.tar.gz
qdoc: Fix heap-use-after-free and memory leak issues
Some of the created nodes appear multiple times in QDoc's node tree. This caused issues with address sanitizer during deletion of the tree: Nodes were checked for their parent() node, and the parent node might have been deleted already. Implement a cleanup function that removes all children that do not report *this* node as their parent from the list of children - after this, the tree can be safely deleted by destroying the root node. Fix memory leak issues; a couple of potential leaks in ClangCodeParser caused by not freeing resources in all cases, and DocBookGenerator leaking a QFile instance per each generated file. Pick-to: 6.2 Fixes: QTBUG-97627 Change-Id: If279b55ee24dc1b7291951ef11b7a26276df167c Reviewed-by: Luca Di Sera <luca.disera@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r--src/qdoc/clangcodeparser.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp
index d61b24270..1b9096e97 100644
--- a/src/qdoc/clangcodeparser.cpp
+++ b/src/qdoc/clangcodeparser.cpp
@@ -1392,11 +1392,11 @@ void ClangCodeParser::buildPCH()
visitor.visitChildren(cur);
qCDebug(lcQdoc) << "PCH built and visited for" << moduleHeader();
}
- clang_disposeTranslationUnit(tu);
} else {
m_pchFileDir->remove();
qCCritical(lcQdoc) << "Could not create PCH file for " << moduleHeader();
}
+ clang_disposeTranslationUnit(tu);
m_args.pop_back(); // remove the "-xc++";
}
}
@@ -1470,6 +1470,7 @@ void ClangCodeParser::parseSourceFile(const Location & /*location*/, const QStri
if (err || !tu) {
qWarning() << "(qdoc) Could not parse source file" << filePath << " error code:" << err;
+ clang_disposeTranslationUnit(tu);
clang_disposeIndex(index_);
return;
}
@@ -1715,6 +1716,7 @@ void ClangCodeParser::printDiagnostics(const CXTranslationUnit &translationUnit)
auto formattedDiagnostic = clang_formatDiagnostic(diagnostic, displayOptions);
qCDebug(lcQdocClang) << clang_getCString(formattedDiagnostic);
clang_disposeString(formattedDiagnostic);
+ clang_disposeDiagnostic(diagnostic);
}
}