Author: Kazu Hirata
Date: 2026-09-03T11:00:17-07:00
New Revision: 35f5599d73fbcb47c00d5e30e3fc3e518a0c3cad

URL: 
https://github.com/llvm/llvm-project/commit/35f5599d73fbcb47c00d5e30e3fc3e518a0c3cad
DIFF: 
https://github.com/llvm/llvm-project/commit/35f5599d73fbcb47c00d5e30e3fc3e518a0c3cad.diff

LOG: [lldb] Fix iterator invalidation in SigchldHandler (#219752)

While SigchldHandler iterates over m_processes with llvm::any_of to
find the process that owns a waitpid event, handling an event can
create or destroy a NativeProcessLinux instance, mutating m_processes.
Comparing iterators after m_processes is mutated (such as the
find_if(...) != end() check in libstdc++'s std::any_of) triggers
assertion failures under epoch checks.

Operating on a temporary copy of m_processes via llvm::to_vector
ensures that iterator traversal is safe from container mutations.

This bug was discovered with tightened epoch checks in
SmallPtrSetIterator.

Assisted-by: Antigravity

Added: 
    

Modified: 
    lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp 
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 6a73999fe0b74..fd7c2557a1fc0 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -403,7 +403,10 @@ void NativeProcessLinux::Manager::SigchldHandler() {
     // vice-versa. This means that if the child event arrives first, it may not
     // be handled by any process (because it doesn't know the thread belongs to
     // it).
-    bool handled = llvm::any_of(m_processes, [&](NativeProcessLinux *process) {
+    // The loop below may modify m_processes (create or delete entries), so
+    // operate on a temporary copy.
+    auto processes = llvm::to_vector(m_processes);
+    bool handled = llvm::any_of(processes, [&](NativeProcessLinux *process) {
       return process->TryHandleWaitStatus(pid, status);
     });
     if (!handled) {


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to