summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-11-03 20:49:17 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-11-03 20:49:17 +0000
commit1f9a45fdfb16188ee9c95a2601602cad0bf1a256 (patch)
tree5adf5446b34639e4d7025370d1af12c4a50a271b /lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
parentb96153481854dd26e03c9b16cea72fcc5492d03e (diff)
downloadbcm5719-llvm-1f9a45fdfb16188ee9c95a2601602cad0bf1a256.tar.gz
bcm5719-llvm-1f9a45fdfb16188ee9c95a2601602cad0bf1a256.zip
Fix a leak found by asan.
llvm-svn: 221179
Diffstat (limited to 'lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp')
-rw-r--r--lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
index 1fb3291f82d..5f0f73ae14c 100644
--- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -872,7 +872,8 @@ private:
void reorderSEHTableEntriesX64(uint8_t *bufferStart);
void addChunk(Chunk *chunk);
- void addSectionChunk(SectionChunk *chunk, SectionHeaderTableChunk *table);
+ void addSectionChunk(std::unique_ptr<SectionChunk> chunk,
+ SectionHeaderTableChunk *table);
void setImageSizeOnDisk();
uint64_t
calcSectionSize(llvm::COFF::SectionCharacteristics sectionType) const;
@@ -982,9 +983,10 @@ void PECOFFWriter::build(const File &linkedFile) {
for (auto i : atoms) {
StringRef sectionName = i.first;
std::vector<const DefinedAtom *> &contents = i.second;
- auto *section = new AtomChunk(_ctx, sectionName, contents);
+ std::unique_ptr<SectionChunk> section(
+ new AtomChunk(_ctx, sectionName, contents));
if (section->size() > 0)
- addSectionChunk(section, sectionTable);
+ addSectionChunk(std::move(section), sectionTable);
}
// Build atom to its RVA map.
@@ -996,12 +998,12 @@ void PECOFFWriter::build(const File &linkedFile) {
// relocated. So we can create the ".reloc" section which contains
// all the relocation sites.
if (_ctx.getBaseRelocationEnabled()) {
- BaseRelocChunk *baseReloc = new BaseRelocChunk(_chunks, _ctx);
+ std::unique_ptr<SectionChunk> baseReloc(new BaseRelocChunk(_chunks, _ctx));
if (baseReloc->size()) {
- addSectionChunk(baseReloc, sectionTable);
+ SectionChunk &ref = *baseReloc;
+ addSectionChunk(std::move(baseReloc), sectionTable);
dataDirectory->setField(DataDirectoryIndex::BASE_RELOCATION_TABLE,
- baseReloc->getVirtualAddress(),
- baseReloc->size());
+ ref.getVirtualAddress(), ref.size());
}
}
@@ -1177,18 +1179,19 @@ void PECOFFWriter::addChunk(Chunk *chunk) {
_chunks.push_back(std::unique_ptr<Chunk>(chunk));
}
-void PECOFFWriter::addSectionChunk(SectionChunk *chunk,
+void PECOFFWriter::addSectionChunk(std::unique_ptr<SectionChunk> chunk,
SectionHeaderTableChunk *table) {
- _chunks.push_back(std::unique_ptr<Chunk>(chunk));
- table->addSection(chunk);
+ SectionChunk &ref = *chunk;
+ _chunks.push_back(std::move(chunk));
+ table->addSection(&ref);
_numSections++;
// Compute and set the starting address of sections when loaded in
// memory. They are different from positions on disk because sections need
// to be sector-aligned on disk but page-aligned in memory.
- chunk->setVirtualAddress(_imageSizeInMemory);
+ ref.setVirtualAddress(_imageSizeInMemory);
_imageSizeInMemory = llvm::RoundUpToAlignment(
- _imageSizeInMemory + chunk->size(), _ctx.getPageSize());
+ _imageSizeInMemory + ref.size(), _ctx.getPageSize());
}
void PECOFFWriter::setImageSizeOnDisk() {
OpenPOWER on IntegriCloud