[compiler-rt] [sanitizer_common] Fix memory leak in ListOfModules (PR #190104)
Andrew Haberlandt via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 21:07:25 PDT 2026
https://github.com/ndrewh created https://github.com/llvm/llvm-project/pull/190104
I found a rather old leak in `ListOfModules`. `ListOfModules` has a member
```
InternalMmapVectorNoCtor<LoadedModule> modules_;
```
Which has neither a constructor nor destructor. As a consequence, we need to call `Destroy` on it when ListOfModules is destroyed, so that the memory is released to the OS (via munmap).
rdar://173906291
>From 6672d2c395a79f4e5186ec70a93964d21ba8b835 Mon Sep 17 00:00:00 2001
From: Andrew Haberlandt <ahaberlandt at apple.com>
Date: Wed, 1 Apr 2026 21:01:04 -0700
Subject: [PATCH] Fix memory leak in ListOfModules
rdar://173906291
---
compiler-rt/lib/sanitizer_common/sanitizer_common.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 564ae301475a9..4dd2187df2272 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -906,7 +906,14 @@ class LoadedModule {
class ListOfModules {
public:
ListOfModules() : initialized(false) {}
- ~ListOfModules() { clear(); }
+ ~ListOfModules() {
+ clear();
+ if (initialized)
+ modules_.Destroy();
+ }
+ ListOfModules(const ListOfModules&) = delete;
+ ListOfModules& operator=(const ListOfModules&) = delete;
+
void init();
void fallbackInit(); // Uses fallback init if available, otherwise clears
const LoadedModule *begin() const { return modules_.begin(); }
More information about the llvm-commits
mailing list