Fix a memory leak from DIE::addSiblingOffset() by adding the DIEValue
authorJeffrey Yasskin <jyasskin@google.com>
Mon, 22 Mar 2010 18:47:14 +0000 (18:47 +0000)
committerJeffrey Yasskin <jyasskin@google.com>
Mon, 22 Mar 2010 18:47:14 +0000 (18:47 +0000)
it allocates to DwarfDebug::DIEValues.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99196 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DIE.cpp
lib/CodeGen/AsmPrinter/DIE.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp

index e97754e5d26fb7bbbfe0ed280a25d96f0a92e075..141c80b38eff7ce1fe64156d0076490a042f08cb 100644 (file)
@@ -114,10 +114,11 @@ DIE::~DIE() {
 
 /// addSiblingOffset - Add a sibling offset field to the front of the DIE.
 ///
-void DIE::addSiblingOffset() {
+DIEValue *DIE::addSiblingOffset() {
   DIEInteger *DI = new DIEInteger(0);
   Values.insert(Values.begin(), DI);
   Abbrev.AddFirstAttribute(dwarf::DW_AT_sibling, dwarf::DW_FORM_ref4);
+  return DI;
 }
 
 #ifndef NDEBUG
index c5909faab7e172abd0d1f6a47c8e8494d8027c37..1a41e2829c2f55edf0318168dfee969eba73fc7a 100644 (file)
@@ -153,7 +153,7 @@ namespace llvm {
     unsigned getOffset() const { return Offset; }
     unsigned getSize() const { return Size; }
     const std::vector<DIE *> &getChildren() const { return Children; }
-    SmallVector<DIEValue*, 32> &getValues() { return Values; }
+    const SmallVector<DIEValue*, 32> &getValues() const { return Values; }
     DIE *getParent() const { return Parent; }
     void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
     void setOffset(unsigned O) { Offset = O; }
@@ -171,8 +171,10 @@ namespace llvm {
     unsigned getSiblingOffset() const { return Offset + Size; }
 
     /// addSiblingOffset - Add a sibling offset field to the front of the DIE.
+    /// The caller is responsible for deleting the return value at or after the
+    /// same time it destroys this DIE.
     ///
-    void addSiblingOffset();
+    DIEValue *addSiblingOffset();
 
     /// addChild - Add a child to the DIE.
     ///
index 7153fe20dcf6da92d6e8008c6d22a18d23bbab28..c935d3a3312fad7e56813ccf109c3193ac5a9baf 100644 (file)
@@ -2351,7 +2351,8 @@ DwarfDebug::computeSizeAndOffset(DIE *Die, unsigned Offset, bool Last) {
   const std::vector<DIE *> &Children = Die->getChildren();
 
   // If not last sibling and has children then add sibling offset attribute.
-  if (!Last && !Children.empty()) Die->addSiblingOffset();
+  if (!Last && !Children.empty())
+    DIEValues.push_back(Die->addSiblingOffset());
 
   // Record the abbreviation.
   assignAbbrevNumber(Die->getAbbrev());
@@ -2465,7 +2466,7 @@ void DwarfDebug::emitDIE(DIE *Die) {
                                 dwarf::TagString(Abbrev->getTag()));
   EmitULEB128(AbbrevNumber);
 
-  SmallVector<DIEValue*, 32> &Values = Die->getValues();
+  const SmallVector<DIEValue*, 32> &Values = Die->getValues();
   const SmallVector<DIEAbbrevData, 8> &AbbrevData = Abbrev->getData();
 
   // Emit the DIE attribute values.