fix MCSectionELF to not leak memory, just like I did for MCSymbol.

MCSectionMachO is already fine (yay for fixed size arrays?),
MCSectionCOFF still leaks.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98537 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-03-15 06:23:52 +00:00
parent c28cc093e3
commit 1f8008cf21
3 changed files with 12 additions and 9 deletions

View File

@@ -42,6 +42,8 @@ namespace llvm {
}; };
class MCSectionCOFF : public MCSection { class MCSectionCOFF : public MCSection {
// FIXME: This memory is leaked because MCSectionCOFF is bump pointer
// allocated and this never gets freed.
std::string Name; std::string Name;
/// IsDirective - This is true if the section name is a directive, not /// IsDirective - This is true if the section name is a directive, not

View File

@@ -21,7 +21,9 @@ namespace llvm {
/// MCSectionELF - This represents a section on linux, lots of unix variants /// MCSectionELF - This represents a section on linux, lots of unix variants
/// and some bare metal systems. /// and some bare metal systems.
class MCSectionELF : public MCSection { class MCSectionELF : public MCSection {
std::string SectionName; /// SectionName - This is the name of the section. The referenced memory is
/// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
StringRef SectionName;
/// Type - This is the sh_type field of a section, drawn from the enums below. /// Type - This is the sh_type field of a section, drawn from the enums below.
unsigned Type; unsigned Type;
@@ -163,10 +165,7 @@ public:
TARGET_INDEP_SHF = FIRST_TARGET_DEP_FLAG-1U TARGET_INDEP_SHF = FIRST_TARGET_DEP_FLAG-1U
}; };
StringRef getSectionName() const { StringRef getSectionName() const { return SectionName; }
return StringRef(SectionName);
}
unsigned getType() const { return Type; } unsigned getType() const { return Type; }
unsigned getFlags() const { return Flags; } unsigned getFlags() const { return Flags; }

View File

@@ -53,11 +53,13 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags,
ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap; ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap;
// Do the lookup, if we have a hit, return it. // Do the lookup, if we have a hit, return it.
const MCSectionELF *&Entry = Map[Section]; StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section);
if (Entry) return Entry; if (Entry.getValue()) return Entry.getValue();
return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, IsExplicit, MCSectionELF *Result = MCSectionELF::Create(Entry.getKey(), Type, Flags, Kind,
getContext()); IsExplicit, getContext());
Entry.setValue(Result);
return Result;
} }
void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,