From 5b78308689121475199c3de365e7aaed8778b6bb Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Wed, 16 Mar 2016 23:29:31 +0000 Subject: [PATCH] Add optional allocator to YAML code to avoid leaking lld atoms. In lld we allocate atoms on an allocator and so don't run their destructors. This means we also shouldn't allocate memory inside them without that also being on an allocator. Reviewed by Lang Hames and Rafael Espindola. llvm-svn: 263676 --- llvm/include/llvm/Support/YAMLTraits.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h index fb2badfd93ba..25680be53d51 100644 --- a/llvm/include/llvm/Support/YAMLTraits.h +++ b/llvm/include/llvm/Support/YAMLTraits.h @@ -894,12 +894,16 @@ private: // to [de]normalize an object for use with YAML conversion. template struct MappingNormalizationHeap { - MappingNormalizationHeap(IO &i_o, TFinal &Obj) + MappingNormalizationHeap(IO &i_o, TFinal &Obj, + llvm::BumpPtrAllocator *allocator = nullptr) : io(i_o), BufPtr(nullptr), Result(Obj) { if ( io.outputting() ) { BufPtr = new (&Buffer) TNorm(io, Obj); } - else { + else if (allocator) { + BufPtr = allocator->Allocate(); + new (BufPtr) TNorm(io); + } else { BufPtr = new TNorm(io); } }