[Lldb-commits] [lldb] [lldb] Fix use after free on ModuleList::RemoveSharedModuleIfOrphaned (PR #155331)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 25 17:58:50 PDT 2025


================
@@ -2564,9 +2564,12 @@ ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec,
           m_images.Append(module_sp, notify);
 
         for (ModuleSP &old_module_sp : replaced_modules) {
+          auto use_count = old_module_sp.use_count();
           Module *old_module_ptr = old_module_sp.get();
           old_module_sp.reset();
-          ModuleList::RemoveSharedModuleIfOrphaned(old_module_ptr);
+          // If the use count was one, this was not in the shared module list.
+          if (use_count > 1)
+            ModuleList::RemoveSharedModuleIfOrphaned(old_module_ptr);
----------------
JDevlieghere wrote:

I realize that this isn't enough to address the issue. But I think this shows what a bad idea it is to mix raw pointers, shared pointer references and references. 

https://github.com/llvm/llvm-project/pull/155331


More information about the lldb-commits mailing list