From 76817eaa413398b702a63c5f51fe4e8d645865d5 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Wed, 19 Nov 2014 18:53:46 +0000 Subject: [PATCH] Fix a temporary MDNode leak. While emitting debug information for function forward decalrations, we create DISubprogram objects that aran't stored in the AllSubprograms list, and thus won't get finalized by the DIBuilder. During the DIBuilder finalize(), the temporary MDNode allocated for the DISubprogram Variables field gets RAUWd with a non temporary DIArray. For the forward declarations, simply delete that temporary node before we delete the parent node, so that it doesn't leak. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222373 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index b2a3f7e0e9..71ccb0d9f9 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -3398,6 +3398,13 @@ void CGDebugInfo::finalize() { VH = p.second; else VH = it->second; + + // Functions have a fake temporary MDNode operand that is supposed + // to get RAUWed upon DIBuilder finalization. Do not leak these + // nodes for the temporary functions we are about to delete. + if (FwdDecl.isSubprogram()) + llvm::MDNode::deleteTemporary(llvm::DISubprogram(FwdDecl).getVariablesNodes()); + FwdDecl.replaceAllUsesWith(CGM.getLLVMContext(), llvm::DIDescriptor(cast(VH))); } -- 2.40.0