diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-07-29 13:53:19 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-07-29 13:53:19 +0000 |
| commit | bccfec653d74b34c1fd064057f29c327377dc0f1 (patch) | |
| tree | 4fb27c1485bfbc77ae239044cbc1455aefdce756 /llvm/lib/MC | |
| parent | c2997dde852dba517a4cc574d4e89eebbd41a713 (diff) | |
| download | bcm5719-llvm-bccfec653d74b34c1fd064057f29c327377dc0f1.tar.gz bcm5719-llvm-bccfec653d74b34c1fd064057f29c327377dc0f1.zip | |
Stop leaking std::strings in GetDwarfFile.
llvm-svn: 109746
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/MCContext.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 7470e8d0031..5812622bb0a 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -213,7 +213,6 @@ unsigned MCContext::GetDwarfFile(StringRef FileName, unsigned FileNumber) { std::pair<StringRef, StringRef> 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<char *>(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<char *>(Allocate(Name.size())); + memcpy(Buf, Name.data(), Name.size()); + File = new (*this) MCDwarfFile(StringRef(Buf, Name.size()), DirIndex); // return the allocated FileNumber. return FileNumber; |

