diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2010-03-22 23:26:12 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2010-03-22 23:26:12 +0000 |
commit | a99d2328035505e364400860fa8114e4666689ed (patch) | |
tree | 3deceb838055c1f8127a13ebd14710b82a6c506d | |
parent | 00c291b01299b42692c3fccffd630515809decc1 (diff) | |
download | bcm5719-llvm-a99d2328035505e364400860fa8114e4666689ed.tar.gz bcm5719-llvm-a99d2328035505e364400860fa8114e4666689ed.zip |
Put MCSectionCOFF::Name into the MCContext instead of leaking it.
llvm-svn: 99231
-rw-r--r-- | llvm/include/llvm/MC/MCSection.h | 7 | ||||
-rw-r--r-- | llvm/lib/MC/MCSection.cpp | 6 |
2 files changed, 8 insertions, 5 deletions
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index 3d8815a7783..4a1c46ccb92 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -42,9 +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; + // The memory for this string is stored in the same MCContext as *this. + StringRef Name; /// IsDirective - This is true if the section name is a directive, not /// something that should be printed with ".section". @@ -61,7 +60,7 @@ namespace llvm { static MCSectionCOFF *Create(StringRef Name, bool IsDirective, SectionKind K, MCContext &Ctx); - const std::string &getName() const { return Name; } + StringRef getName() const { return Name; } bool isDirective() const { return IsDirective; } virtual void PrintSwitchToSection(const MCAsmInfo &MAI, diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp index 24c89efefc6..f6e96368eb2 100644 --- a/llvm/lib/MC/MCSection.cpp +++ b/llvm/lib/MC/MCSection.cpp @@ -26,7 +26,11 @@ MCSection::~MCSection() { MCSectionCOFF *MCSectionCOFF:: Create(StringRef Name, bool IsDirective, SectionKind K, MCContext &Ctx) { - return new (Ctx) MCSectionCOFF(Name, IsDirective, K); + char *NameCopy = static_cast<char*>( + Ctx.Allocate(Name.size(), /*Alignment=*/1)); + memcpy(NameCopy, Name.data(), Name.size()); + return new (Ctx) MCSectionCOFF(StringRef(NameCopy, Name.size()), + IsDirective, K); } void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, |