[lld] r265497 - Fix a memory leak found by check-lld asan tests.
Ivan Krasin via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 5 18:11:12 PDT 2016
Author: krasin
Date: Tue Apr 5 20:11:10 2016
New Revision: 265497
URL: http://llvm.org/viewvc/llvm-project?rev=265497&view=rev
Log:
Fix a memory leak found by check-lld asan tests.
Summary:
This bug was introduced by http://reviews.llvm.org/rL265059,
where InputSectionBase got Thunks field, which can do memory allocations.
Since InputSectionBase destructors were never called (I count it as another bug),
that caused a memory leak when 2 or more thunks are added to a section.
The fix to is properly call InputSectionBase destructors from ~ObjectFile.
Reviewers: atanasyan, ruiu, rafael
Subscribers: rafael, krasin, pcc
Differential Revision: http://reviews.llvm.org/D18809
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=265497&r1=265496&r2=265497&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Apr 5 20:11:10 2016
@@ -204,7 +204,7 @@ void elf::ObjectFile<ELFT>::initializeSe
// If -r is given, we do not interpret or apply relocation
// but just copy relocation sections to output.
if (Config->Relocatable) {
- Sections[I] = new (Alloc) InputSection<ELFT>(this, &Sec);
+ Sections[I] = new (IAlloc.Allocate()) InputSection<ELFT>(this, &Sec);
break;
}
@@ -278,7 +278,7 @@ elf::ObjectFile<ELFT>::createInputSectio
return new (EHAlloc.Allocate()) EHInputSection<ELFT>(this, &Sec);
if (shouldMerge<ELFT>(Sec))
return new (MAlloc.Allocate()) MergeInputSection<ELFT>(this, &Sec);
- return new (Alloc) InputSection<ELFT>(this, &Sec);
+ return new (IAlloc.Allocate()) InputSection<ELFT>(this, &Sec);
}
template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() {
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=265497&r1=265496&r2=265497&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Tue Apr 5 20:11:10 2016
@@ -149,6 +149,7 @@ private:
MipsReginfoInputSection<ELFT> *MipsReginfo = nullptr;
llvm::BumpPtrAllocator Alloc;
+ llvm::SpecificBumpPtrAllocator<InputSection<ELFT>> IAlloc;
llvm::SpecificBumpPtrAllocator<MergeInputSection<ELFT>> MAlloc;
llvm::SpecificBumpPtrAllocator<EHInputSection<ELFT>> EHAlloc;
};
More information about the llvm-commits
mailing list