diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-03-30 13:28:42 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-03-30 13:28:42 +0000 |
commit | 80ae570c127debaa26bc45599ead875764e2d085 (patch) | |
tree | ad42103adc24acd41a95a97c4bc4c54f30a8824e /lib/Target/PIC16/PIC16Section.cpp | |
parent | 12b4ddadf69d8820ec7763eeb46e18440763f0f0 (diff) | |
download | external_llvm-80ae570c127debaa26bc45599ead875764e2d085.zip external_llvm-80ae570c127debaa26bc45599ead875764e2d085.tar.gz external_llvm-80ae570c127debaa26bc45599ead875764e2d085.tar.bz2 |
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).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PIC16/PIC16Section.cpp')
-rw-r--r-- | lib/Target/PIC16/PIC16Section.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/Target/PIC16/PIC16Section.cpp b/lib/Target/PIC16/PIC16Section.cpp index a96ebb8..2505b11 100644 --- a/lib/Target/PIC16/PIC16Section.cpp +++ b/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; } |