summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/PIC16/PIC16Section.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-03-30 13:28:42 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-03-30 13:28:42 +0000
commit7cc264bf195ac57998d9eedf0cf80a3db111e563 (patch)
tree548dd3690d3d00022d7b60110bcdfbb0662dcf80 /llvm/lib/Target/PIC16/PIC16Section.cpp
parentcc1db611807f222f3d0aaf0b3ecfdc7c2880ead1 (diff)
downloadbcm5719-llvm-7cc264bf195ac57998d9eedf0cf80a3db111e563.tar.gz
bcm5719-llvm-7cc264bf195ac57998d9eedf0cf80a3db111e563.zip
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). llvm-svn: 99887
Diffstat (limited to 'llvm/lib/Target/PIC16/PIC16Section.cpp')
-rw-r--r--llvm/lib/Target/PIC16/PIC16Section.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Target/PIC16/PIC16Section.cpp b/llvm/lib/Target/PIC16/PIC16Section.cpp
index a96ebb8d8e3..2505b111f1e 100644
--- a/llvm/lib/Target/PIC16/PIC16Section.cpp
+++ b/llvm/lib/Target/PIC16/PIC16Section.cpp
@@ -17,10 +17,9 @@ using namespace llvm;
// 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 @@ PIC16Section *PIC16Section::Create(const StringRef &Name,
}
+ // 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;
}
OpenPOWER on IntegriCloud