[TextAPI] Fix memory leak in SymbolSet. (#150589)
The SymbolSet class bump-ptr-allocates Symbol objects, but Symbol has a non-trivial destructor (since Symbol's Targets member is a SmallVector): we need to explicitly destroy the Symbol objects to ensure that no memory is leaked. rdar://154778728
This commit is contained in:
parent
2e3fd547de
commit
1299bba404
@ -92,6 +92,7 @@ private:
|
||||
|
||||
public:
|
||||
SymbolSet() = default;
|
||||
~SymbolSet();
|
||||
LLVM_ABI Symbol *addGlobal(EncodeKind Kind, StringRef Name, SymbolFlags Flags,
|
||||
const Target &Targ);
|
||||
size_t size() const { return Symbols.size(); }
|
||||
|
@ -11,6 +11,11 @@
|
||||
using namespace llvm;
|
||||
using namespace llvm::MachO;
|
||||
|
||||
SymbolSet::~SymbolSet() {
|
||||
for (auto &[Key, Sym] : Symbols)
|
||||
Sym->~Symbol();
|
||||
}
|
||||
|
||||
Symbol *SymbolSet::addGlobalImpl(EncodeKind Kind, StringRef Name,
|
||||
SymbolFlags Flags) {
|
||||
Name = copyString(Name);
|
||||
|
20
llvm/test/tools/llvm-readtapi/many-targets.test
Normal file
20
llvm/test/tools/llvm-readtapi/many-targets.test
Normal file
@ -0,0 +1,20 @@
|
||||
; RUN: rm -rf %t
|
||||
; RUN: split-file %s %t
|
||||
;
|
||||
; RUN: llvm-readtapi %t/many-targets.tbd
|
||||
;
|
||||
; Check that tbds containing symbols with many targets parse correctly (and in
|
||||
; particular parse without leaks).
|
||||
|
||||
;--- many-targets.tbd
|
||||
--- !tapi-tbd
|
||||
tbd-version: 4
|
||||
targets: [ x86_64-macos, x86_64-maccatalyst, arm64-macos, arm64-maccatalyst,
|
||||
arm64e-macos, arm64e-maccatalyst, arm64-ios, arm64e-ios ]
|
||||
install-name: '/usr/lib/foo.dylib'
|
||||
current-version: 1
|
||||
exports:
|
||||
- targets: [ x86_64-macos, x86_64-maccatalyst, arm64-macos, arm64-maccatalyst,
|
||||
arm64e-macos, arm64e-maccatalyst, arm64-ios, arm64e-ios ]
|
||||
symbols: [ 'foo' ]
|
||||
...
|
Loading…
x
Reference in New Issue
Block a user