mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[llvm-profdata] Fix use-after-free from discarded MemoryBuffer (NFC)
Thanks to Justin Bogner for pointing this out! Caught by ASAN. llvm-svn: 271748
This commit is contained in:
parent
af3cf63542
commit
56ea31445a
@ -223,16 +223,19 @@ static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {
|
||||
return WeightedFile(FileName, Weight);
|
||||
}
|
||||
|
||||
static void parseInputFilenamesFile(const StringRef &InputFilenamesFile,
|
||||
WeightedFileVector &WFV) {
|
||||
static std::unique_ptr<MemoryBuffer>
|
||||
parseInputFilenamesFile(const StringRef &InputFilenamesFile,
|
||||
WeightedFileVector &WFV) {
|
||||
if (InputFilenamesFile == "")
|
||||
return;
|
||||
return {};
|
||||
|
||||
auto Buf = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
|
||||
if (!Buf)
|
||||
exitWithErrorCode(Buf.getError(), InputFilenamesFile);
|
||||
auto BufOrError = MemoryBuffer::getFileOrSTDIN(InputFilenamesFile);
|
||||
if (!BufOrError)
|
||||
exitWithErrorCode(BufOrError.getError(), InputFilenamesFile);
|
||||
|
||||
std::unique_ptr<MemoryBuffer> Buffer = std::move(*BufOrError);
|
||||
StringRef Data = Buffer->getBuffer();
|
||||
|
||||
StringRef Data = Buf.get()->getBuffer();
|
||||
SmallVector<StringRef, 8> Entries;
|
||||
Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
|
||||
for (const StringRef &FileWeightEntry : Entries) {
|
||||
@ -246,6 +249,8 @@ static void parseInputFilenamesFile(const StringRef &InputFilenamesFile,
|
||||
else
|
||||
WFV.emplace_back(parseWeightedFile(SanitizedEntry));
|
||||
}
|
||||
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
static int merge_main(int argc, const char *argv[]) {
|
||||
@ -288,7 +293,7 @@ static int merge_main(int argc, const char *argv[]) {
|
||||
WeightedInputs.push_back(WeightedFile(Filename, 1));
|
||||
for (StringRef WeightedFilename : WeightedInputFilenames)
|
||||
WeightedInputs.push_back(parseWeightedFile(WeightedFilename));
|
||||
parseInputFilenamesFile(InputFilenamesFile, WeightedInputs);
|
||||
auto Buf = parseInputFilenamesFile(InputFilenamesFile, WeightedInputs);
|
||||
|
||||
if (WeightedInputs.empty())
|
||||
exitWithError("No input files specified. See " +
|
||||
|
Loading…
x
Reference in New Issue
Block a user