From: Justin Bogner Date: Thu, 3 Nov 2016 18:28:04 +0000 (+0000) Subject: PDB: Fix some APIs to avoid use-after-frees X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1787ec76dd36ee278b2014af806a46513c047d4a;p=llvm PDB: Fix some APIs to avoid use-after-frees The buffer is already owned by the PDBFile for all of these APIs, so don't pass it in separately. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285953 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h b/include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h index 749a8662fb7..0784b5ee781 100644 --- a/include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h +++ b/include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h @@ -59,8 +59,7 @@ public: Error finalizeMsfLayout(); - Expected> build(PDBFile &File, - const msf::WritableStream &Buffer); + Expected> build(PDBFile &File); Error commit(const msf::MSFLayout &Layout, const msf::WritableStream &Buffer); diff --git a/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h b/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h index f7a66c18f57..5afbf820a0c 100644 --- a/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h +++ b/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h @@ -43,8 +43,7 @@ public: Error finalizeMsfLayout(); - Expected> - build(PDBFile &File, const msf::WritableStream &Buffer); + Expected> build(PDBFile &File); Error commit(const msf::MSFLayout &Layout, const msf::WritableStream &Buffer) const; diff --git a/include/llvm/DebugInfo/PDB/Raw/TpiStreamBuilder.h b/include/llvm/DebugInfo/PDB/Raw/TpiStreamBuilder.h index 2248fc8875b..937b188e96e 100644 --- a/include/llvm/DebugInfo/PDB/Raw/TpiStreamBuilder.h +++ b/include/llvm/DebugInfo/PDB/Raw/TpiStreamBuilder.h @@ -56,8 +56,7 @@ public: Error finalizeMsfLayout(); - Expected> build(PDBFile &File, - const msf::WritableStream &Buffer); + Expected> build(PDBFile &File); Error commit(const msf::MSFLayout &Layout, const msf::WritableStream &Buffer); diff --git a/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp b/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp index 4ee28c7d811..6067e5ce842 100644 --- a/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp +++ b/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp @@ -328,15 +328,15 @@ std::vector DbiStreamBuilder::createSectionMap( } Expected> -DbiStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) { +DbiStreamBuilder::build(PDBFile &File) { if (!VerHeader.hasValue()) return make_error(raw_error_code::unspecified, "Missing DBI Stream Version"); if (auto EC = finalize()) return std::move(EC); - auto StreamData = MappedBlockStream::createIndexedStream(File.getMsfLayout(), - Buffer, StreamDBI); + auto StreamData = MappedBlockStream::createIndexedStream( + File.getMsfLayout(), File.getMsfBuffer(), StreamDBI); auto Dbi = llvm::make_unique(File, std::move(StreamData)); Dbi->Header = Header; Dbi->FileInfoSubstream = ReadableStreamRef(FileInfoBuffer); diff --git a/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp b/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp index 991e32d4ac7..e909c30e95f 100644 --- a/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp +++ b/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp @@ -48,9 +48,9 @@ Error InfoStreamBuilder::finalizeMsfLayout() { } Expected> -InfoStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) { - auto StreamData = MappedBlockStream::createIndexedStream(File.getMsfLayout(), - Buffer, StreamPDB); +InfoStreamBuilder::build(PDBFile &File) { + auto StreamData = MappedBlockStream::createIndexedStream( + File.getMsfLayout(), File.getMsfBuffer(), StreamPDB); auto Info = llvm::make_unique(std::move(StreamData)); Info->Version = Ver; Info->Signature = Sig; diff --git a/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp b/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp index dcd8662913c..e47d11cf61a 100644 --- a/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp +++ b/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp @@ -97,28 +97,28 @@ PDBFileBuilder::build(std::unique_ptr PdbFileBuffer) { File->ContainerLayout = *ExpectedLayout; if (Info) { - auto ExpectedInfo = Info->build(*File, *PdbFileBuffer); + auto ExpectedInfo = Info->build(*File); if (!ExpectedInfo) return ExpectedInfo.takeError(); File->Info = std::move(*ExpectedInfo); } if (Dbi) { - auto ExpectedDbi = Dbi->build(*File, *PdbFileBuffer); + auto ExpectedDbi = Dbi->build(*File); if (!ExpectedDbi) return ExpectedDbi.takeError(); File->Dbi = std::move(*ExpectedDbi); } if (Tpi) { - auto ExpectedTpi = Tpi->build(*File, *PdbFileBuffer); + auto ExpectedTpi = Tpi->build(*File); if (!ExpectedTpi) return ExpectedTpi.takeError(); File->Tpi = std::move(*ExpectedTpi); } if (Ipi) { - auto ExpectedIpi = Ipi->build(*File, *PdbFileBuffer); + auto ExpectedIpi = Ipi->build(*File); if (!ExpectedIpi) return ExpectedIpi.takeError(); File->Ipi = std::move(*ExpectedIpi); diff --git a/lib/DebugInfo/PDB/Raw/TpiStreamBuilder.cpp b/lib/DebugInfo/PDB/Raw/TpiStreamBuilder.cpp index 733efe882a2..d8bae59195c 100644 --- a/lib/DebugInfo/PDB/Raw/TpiStreamBuilder.cpp +++ b/lib/DebugInfo/PDB/Raw/TpiStreamBuilder.cpp @@ -99,16 +99,15 @@ Error TpiStreamBuilder::finalizeMsfLayout() { return Error::success(); } -Expected> -TpiStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) { +Expected> TpiStreamBuilder::build(PDBFile &File) { if (!VerHeader.hasValue()) return make_error(raw_error_code::unspecified, "Missing TPI Stream Version"); if (auto EC = finalize()) return std::move(EC); - auto StreamData = - MappedBlockStream::createIndexedStream(File.getMsfLayout(), Buffer, Idx); + auto StreamData = MappedBlockStream::createIndexedStream( + File.getMsfLayout(), File.getMsfBuffer(), Idx); auto Tpi = llvm::make_unique(File, std::move(StreamData)); Tpi->Header = Header; Tpi->TypeRecords = VarStreamArray(TypeRecordStream);