DIE: Pass ownership of children via std::unique_ptr rather than raw pointer.

This should reduce the chance of memory leaks like those fixed in
r207240.

There's still some unclear ownership of DIEs happening in DwarfDebug.
Pushing unique_ptr and references through more APIs should help expose
the cases where ownership is a bit fuzzy.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207263 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie
2014-04-25 20:00:34 +00:00
parent 172515f0be
commit 12d5224df6
6 changed files with 106 additions and 100 deletions

View File

@ -383,7 +383,7 @@ void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) {
assert(Tag != dwarf::DW_TAG_auto_variable &&
Tag != dwarf::DW_TAG_arg_variable);
Parent.addChild(new DIE((dwarf::Tag)Tag));
Parent.addChild(make_unique<DIE>((dwarf::Tag)Tag));
DIE &Die = *Parent.getChildren().back();
if (N)
insertDIE(N, &Die);
@ -1793,18 +1793,19 @@ void DwarfUnit::constructContainingTypeDIEs() {
}
/// constructVariableDIE - Construct a DIE for the given DbgVariable.
DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
std::unique_ptr<DIE> DwarfUnit::constructVariableDIE(DbgVariable &DV,
bool isScopeAbstract) {
auto D = constructVariableDIEImpl(DV, isScopeAbstract);
DV.setDIE(*D);
return D;
}
DIE *DwarfUnit::constructVariableDIEImpl(const DbgVariable &DV,
bool isScopeAbstract) {
std::unique_ptr<DIE> DwarfUnit::constructVariableDIEImpl(const DbgVariable &DV,
bool isScopeAbstract) {
StringRef Name = DV.getName();
// Define variable debug information entry.
DIE *VariableDie = new DIE(DV.getTag());
auto VariableDie = make_unique<DIE>(DV.getTag());
DbgVariable *AbsVar = DV.getAbstractVariable();
DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : nullptr;
if (AbsDIE)