Skip to content

Commit 3e9b26d

Browse files
lhamesmahesh-attarde
authored andcommitted
[TextAPI] Fix memory leak in SymbolSet. (llvm#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
1 parent fb2f112 commit 3e9b26d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

llvm/include/llvm/TextAPI/SymbolSet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class SymbolSet {
9292

9393
public:
9494
SymbolSet() = default;
95+
~SymbolSet();
9596
LLVM_ABI Symbol *addGlobal(EncodeKind Kind, StringRef Name, SymbolFlags Flags,
9697
const Target &Targ);
9798
size_t size() const { return Symbols.size(); }

llvm/lib/TextAPI/SymbolSet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
using namespace llvm;
1212
using namespace llvm::MachO;
1313

14+
SymbolSet::~SymbolSet() {
15+
for (auto &[Key, Sym] : Symbols)
16+
Sym->~Symbol();
17+
}
18+
1419
Symbol *SymbolSet::addGlobalImpl(EncodeKind Kind, StringRef Name,
1520
SymbolFlags Flags) {
1621
Name = copyString(Name);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
;
4+
; RUN: llvm-readtapi %t/many-targets.tbd
5+
;
6+
; Check that tbds containing symbols with many targets parse correctly (and in
7+
; particular parse without leaks).
8+
9+
;--- many-targets.tbd
10+
--- !tapi-tbd
11+
tbd-version: 4
12+
targets: [ x86_64-macos, x86_64-maccatalyst, arm64-macos, arm64-maccatalyst,
13+
arm64e-macos, arm64e-maccatalyst, arm64-ios, arm64e-ios ]
14+
install-name: '/usr/lib/foo.dylib'
15+
current-version: 1
16+
exports:
17+
- targets: [ x86_64-macos, x86_64-maccatalyst, arm64-macos, arm64-maccatalyst,
18+
arm64e-macos, arm64e-maccatalyst, arm64-ios, arm64e-ios ]
19+
symbols: [ 'foo' ]
20+
...

0 commit comments

Comments
 (0)