[all-commits] [llvm/llvm-project] c7689f: [Clang] Fix memory leak due to TemplateArgumentLis...
Andrew Browne via All-commits
all-commits at lists.llvm.org
Wed Jun 8 09:58:53 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: c7689fd552cdf2b37e804a59322bd0661ccdd3c5
https://github.com/llvm/llvm-project/commit/c7689fd552cdf2b37e804a59322bd0661ccdd3c5
Author: Andrew Browne <browneee at google.com>
Date: 2022-06-08 (Wed, 08 Jun 2022)
Changed paths:
M clang-tools-extra/clangd/AST.cpp
M clang/docs/ReleaseNotes.rst
M clang/include/clang/AST/DeclTemplate.h
M clang/include/clang/AST/TemplateBase.h
M clang/lib/AST/ASTImporter.cpp
M clang/lib/AST/DeclTemplate.cpp
M clang/lib/AST/TemplateBase.cpp
M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Log Message:
-----------
[Clang] Fix memory leak due to TemplateArgumentListInfo used in AST node.
It looks like the leak is rooted at the allocation here:
https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L3857
The VarTemplateSpecializationDecl is allocated using placement new which uses the AST structure for ownership: https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/AST/DeclBase.cpp#L99
The problem is the TemplateArgumentListInfo inside https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/DeclTemplate.h#L2721
This object contains a vector which does not use placement new: https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L564
Apparently ASTTemplateArgumentListInfo should be used instead https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L575
https://reviews.llvm.org/D125802#3551305
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D126944
More information about the All-commits
mailing list