This is an archive of the discontinued LLVM Phabricator instance.

[MainLoop] Fix possible use of an invalid iterator
ClosedPublic

Authored by petpav01 on Jul 12 2017, 3:02 AM.

Details

Summary

Store file descriptors from loop.m_read_fds (if FORCE_PSELECT is defined) and signals from loop.m_signals that need to be processed in MainLoop::RunImpl::ProcessEvents() into a separate vector and then iterate over this container to invoke the callbacks.

This prevents a problem where when the code iterated directly over m_read_fds/m_signals, a callback invoked from within the loop could modify these variables and invalidate the loop iterator. This would then result in the following assertion failure:

llvm/include/llvm/ADT/DenseMap.h:1099: llvm::DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConst>& llvm::DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConst>::operator++() [with KeyT = int; ValueT = std::function<void(lldb_private::MainLoopBase&)>; KeyInfoT = llvm::DenseMapInfo<int>; Bucket = llvm::detail::DenseMapPair<int, std::function<void(lldb_private::MainLoopBase&)> >; bool IsConst = false]: assertion "isHandleInSync() && "invalid iterator access!"" failed

Diff Detail

Repository
rL LLVM

Event Timeline

petpav01 created this revision.Jul 12 2017, 3:02 AM
labath accepted this revision.Jul 12 2017, 3:25 AM

Looks great, thanks for catching this.

The code was doing it this way initially, but then this got lost with all the frantic refactors.

This revision is now accepted and ready to land.Jul 12 2017, 3:25 AM
This revision was automatically updated to reflect the committed changes.