[llvm-commits] [llvm] r99231 - in /llvm/trunk: include/llvm/MC/MCSection.h lib/MC/MCSection.cpp

Jeffrey Yasskin jyasskin at google.com
Mon Mar 22 16:26:13 PDT 2010


Author: jyasskin
Date: Mon Mar 22 18:26:12 2010
New Revision: 99231

URL: http://llvm.org/viewvc/llvm-project?rev=99231&view=rev
Log:
Put MCSectionCOFF::Name into the MCContext instead of leaking it.

Modified:
    llvm/trunk/include/llvm/MC/MCSection.h
    llvm/trunk/lib/MC/MCSection.cpp

Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=99231&r1=99230&r2=99231&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Mon Mar 22 18:26:12 2010
@@ -42,9 +42,8 @@
   };
 
   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 @@
     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,

Modified: llvm/trunk/lib/MC/MCSection.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSection.cpp?rev=99231&r1=99230&r2=99231&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSection.cpp (original)
+++ llvm/trunk/lib/MC/MCSection.cpp Mon Mar 22 18:26:12 2010
@@ -26,7 +26,11 @@
 
 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,





More information about the llvm-commits mailing list