[llvm-commits] [llvm] r99887 - in /llvm/trunk/lib/Target/PIC16: PIC16Section.cpp PIC16Section.h
Benjamin Kramer
benny.kra at googlemail.com
Tue Mar 30 06:28:42 PDT 2010
Author: d0k
Date: Tue Mar 30 08:28:42 2010
New Revision: 99887
URL: http://llvm.org/viewvc/llvm-project?rev=99887&view=rev
Log:
PIC16: Plug a leak in PIC16Section by allocating name & address strings in the
MCContext. There is still one leak left in PIC16Section (the Items vector).
Modified:
llvm/trunk/lib/Target/PIC16/PIC16Section.cpp
llvm/trunk/lib/Target/PIC16/PIC16Section.h
Modified: llvm/trunk/lib/Target/PIC16/PIC16Section.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Section.cpp?rev=99887&r1=99886&r2=99887&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Section.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Section.cpp Tue Mar 30 08:28:42 2010
@@ -17,10 +17,9 @@
// This is the only way to create a PIC16Section. Sections created here
// do not need to be explicitly deleted as they are managed by auto_ptrs.
-PIC16Section *PIC16Section::Create(const StringRef &Name,
- PIC16SectionType Ty,
- const std::string &Address,
- int Color, MCContext &Ctx) {
+PIC16Section *PIC16Section::Create(StringRef Name, PIC16SectionType Ty,
+ StringRef Address, int Color,
+ MCContext &Ctx) {
/// Determine the internal SectionKind info.
/// Users of PIC16Section class should not need to know the internal
@@ -59,8 +58,17 @@
}
+ // Copy strings into context allocated memory so they get free'd when the
+ // context is destroyed.
+ char *NameCopy = static_cast<char*>(Ctx.Allocate(Name.size(), 1));
+ memcpy(NameCopy, Name.data(), Name.size());
+ char *AddressCopy = static_cast<char*>(Ctx.Allocate(Address.size(), 1));
+ memcpy(AddressCopy, Address.data(), Address.size());
+
// Create the Section.
- PIC16Section *S = new (Ctx) PIC16Section(Name, K, Address, Color);
+ PIC16Section *S =
+ new (Ctx) PIC16Section(StringRef(NameCopy, Name.size()), K,
+ StringRef(AddressCopy, Address.size()), Color);
S->T = Ty;
return S;
}
Modified: llvm/trunk/lib/Target/PIC16/PIC16Section.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16Section.h?rev=99887&r1=99886&r2=99887&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16Section.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16Section.h Tue Mar 30 08:28:42 2010
@@ -30,11 +30,11 @@
PIC16SectionType T;
/// Name of the section to uniquely identify it.
- std::string Name;
+ StringRef Name;
/// User can specify an address at which a section should be placed.
/// Negative value here means user hasn't specified any.
- std::string Address;
+ StringRef Address;
/// Overlay information - Sections with same color can be overlaid on
/// one another.
@@ -43,17 +43,16 @@
/// Total size of all data objects contained here.
unsigned Size;
- PIC16Section(const StringRef &name, SectionKind K, const std::string &addr,
- int color)
+ PIC16Section(StringRef name, SectionKind K, StringRef addr, int color)
: MCSection(K), Name(name), Address(addr), Color(color), Size(0) {
}
public:
/// Return the name of the section.
- const std::string &getName() const { return Name; }
+ StringRef getName() const { return Name; }
/// Return the Address of the section.
- const std::string &getAddress() const { return Address; }
+ StringRef getAddress() const { return Address; }
/// Return the Color of the section.
int getColor() const { return Color; }
@@ -77,8 +76,8 @@
PIC16SectionType getType() const { return T; }
/// This would be the only way to create a section.
- static PIC16Section *Create(const StringRef &Name, PIC16SectionType Ty,
- const std::string &Address, int Color,
+ static PIC16Section *Create(StringRef Name, PIC16SectionType Ty,
+ StringRef Address, int Color,
MCContext &Ctx);
/// Override this as PIC16 has its own way of printing switching
More information about the llvm-commits
mailing list