};
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".
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,
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,