From 3bce5adb32fbbe5c5549b902f4d65737f40c1499 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 29 Jul 2010 13:53:19 +0000 Subject: Stop leaking std::strings in GetDwarfFile. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109746 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCContext.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/MC/MCContext.cpp') diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 7470e8d003..5812622bb0 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -213,7 +213,6 @@ unsigned MCContext::GetDwarfFile(StringRef FileName, unsigned FileNumber) { std::pair Slash = FileName.rsplit('/'); // Find or make a entry in the MCDwarfDirs vector for this Directory. - StringRef Directory; StringRef Name; unsigned DirIndex; // Capture directory name. @@ -221,23 +220,24 @@ unsigned MCContext::GetDwarfFile(StringRef FileName, unsigned FileNumber) { Name = Slash.first; DirIndex = 0; // For FileNames with no directories a DirIndex of 0 is used. } else { - Directory = Slash.first; + StringRef Directory = Slash.first; Name = Slash.second; for (DirIndex = 1; DirIndex < MCDwarfDirs.size(); DirIndex++) { - std::string *&Dir = MCDwarfDirs[DirIndex]; - if (Directory == *Dir) + if (Directory == MCDwarfDirs[DirIndex]) break; } if (DirIndex >= MCDwarfDirs.size()) { - MCDwarfDirs.resize(DirIndex + 1); - std::string *&NewDir = MCDwarfDirs[DirIndex]; - NewDir = new (*this) std::string(Directory); + char *Buf = static_cast(Allocate(Directory.size())); + memcpy(Buf, Directory.data(), Directory.size()); + MCDwarfDirs.push_back(StringRef(Buf, Directory.size())); } } // Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles // vector. - File = new (*this) MCDwarfFile(Name, DirIndex); + char *Buf = static_cast(Allocate(Name.size())); + memcpy(Buf, Name.data(), Name.size()); + File = new (*this) MCDwarfFile(StringRef(Buf, Name.size()), DirIndex); // return the allocated FileNumber. return FileNumber; -- cgit v1.2.3