[PATCH] D126944: [Clang] Fix memory leak due to TemplateArgumentListInfo used in AST node.

Andrew via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 2 21:59:26 PDT 2022


browneee created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman, martong.
Herald added a reviewer: shafik.
Herald added a project: All.
browneee requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126944

Files:
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126944.433950.patch
Type: text/x-patch
Size: 8037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220603/42ec6fa7/attachment.bin>


More information about the cfe-commits mailing list