From 977b1f574fa18219fde5f709b906c79202ef1916 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Thu, 17 Feb 2022 22:01:29 +0100 Subject: [PATCH] [clang][ASTReader] Fix memory leak while reading FriendTemplateDecls Allocate on ASTContext, rather than just on heap, so that template parameter lists are freed up. Differential Revision: https://reviews.llvm.org/D120081 --- clang/lib/Serialization/ASTReaderDecl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 25d7e9e6a2e6..29bef2aa2089 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2103,7 +2103,7 @@ void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { VisitDecl(D); unsigned NumParams = Record.readInt(); D->NumParams = NumParams; - D->Params = new TemplateParameterList*[NumParams]; + D->Params = new (Reader.getContext()) TemplateParameterList *[NumParams]; for (unsigned i = 0; i != NumParams; ++i) D->Params[i] = Record.readTemplateParameterList(); if (Record.readInt()) // HasFriendDecl