[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:55:39 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:
Why does `RemoveSharedModuleIfOrphaned` take a raw pointer and not the `ModuleSP`? If it did, then we could just check if the SP is valid (like `Remove` does) and avoid yet another place where we check the use count.
https://github.com/llvm/llvm-project/pull/155331
More information about the lldb-commits
mailing list