https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/219752
While SigchldHandler iterates over m_processes with llvm::any_of to find the process that owns a waitpid event, handling an event can destroy a NativeProcessLinux instance and erase it from m_processes. Continuing the iteration with invalidated iterators triggers assertion failures under epoch checks. Snapshotting m_processes into a vector with llvm::to_vector before the loop ensures that iterator traversal is safe from container mutations. This bug was discovered with tightened epoch checks in SmallPtrSetIterator. Assisted-by: Antigravity >From b85340e55d1423f20c29946d0a7f72dda037541d Mon Sep 17 00:00:00 2001 From: Kazu Hirata <[email protected]> Date: Sat, 29 Aug 2026 19:19:39 -0700 Subject: [PATCH] [lldb] Fix iterator invalidation in SigchldHandler While SigchldHandler iterates over m_processes with llvm::any_of to find the process that owns a waitpid event, handling an event can destroy a NativeProcessLinux instance and erase it from m_processes. Continuing the iteration with invalidated iterators triggers assertion failures under epoch checks. Snapshotting m_processes into a vector with llvm::to_vector before the loop ensures that iterator traversal is safe from container mutations. This bug was discovered with tightened epoch checks in SmallPtrSetIterator. Assisted-by: Antigravity --- lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index 6a73999fe0b74..52f4b50e96517 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -403,7 +403,8 @@ 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) { + 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
