diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-03-15 06:23:52 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-03-15 06:23:52 +0000 |
| commit | 632eb65cd2315c68e4a43ef5950cd31e82adf7cb (patch) | |
| tree | 6c5939a627e01f8d5f33af9375ccc58ae0fa1ba5 /llvm | |
| parent | 133487696abe700b10a096680db651b37c6b8846 (diff) | |
| download | bcm5719-llvm-632eb65cd2315c68e4a43ef5950cd31e82adf7cb.tar.gz bcm5719-llvm-632eb65cd2315c68e4a43ef5950cd31e82adf7cb.zip | |
fix MCSectionELF to not leak memory, just like I did for MCSymbol.
MCSectionMachO is already fine (yay for fixed size arrays?),
MCSectionCOFF still leaks.
llvm-svn: 98537
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/MC/MCSection.h | 2 | ||||
| -rw-r--r-- | llvm/include/llvm/MC/MCSectionELF.h | 9 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 10 |
3 files changed, 12 insertions, 9 deletions
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index ceb6d278c9c..3d8815a7783 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -42,6 +42,8 @@ namespace llvm { }; class MCSectionCOFF : public MCSection { + // FIXME: This memory is leaked because MCSectionCOFF is bump pointer + // allocated and this never gets freed. std::string Name; /// IsDirective - This is true if the section name is a directive, not diff --git a/llvm/include/llvm/MC/MCSectionELF.h b/llvm/include/llvm/MC/MCSectionELF.h index 2dccf5c5728..41c17bd8fa1 100644 --- a/llvm/include/llvm/MC/MCSectionELF.h +++ b/llvm/include/llvm/MC/MCSectionELF.h @@ -21,7 +21,9 @@ namespace llvm { /// MCSectionELF - This represents a section on linux, lots of unix variants /// and some bare metal systems. 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. unsigned Type; @@ -163,10 +165,7 @@ public: TARGET_INDEP_SHF = FIRST_TARGET_DEP_FLAG-1U }; - StringRef getSectionName() const { - return StringRef(SectionName); - } - + StringRef getSectionName() const { return SectionName; } unsigned getType() const { return Type; } unsigned getFlags() const { return Flags; } diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 788bbf11908..05e0ea8dfc1 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -53,11 +53,13 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags, ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap; // Do the lookup, if we have a hit, return it. - const MCSectionELF *&Entry = Map[Section]; - if (Entry) return Entry; + StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section); + if (Entry.getValue()) return Entry.getValue(); - return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, IsExplicit, - getContext()); + MCSectionELF *Result = MCSectionELF::Create(Entry.getKey(), Type, Flags, Kind, + IsExplicit, getContext()); + Entry.setValue(Result); + return Result; } void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx, |

